Boost C++ Libraries: Ticket #8057: Add constexpr + noexcept for atomic https://svn.boost.org/trac10/ticket/8057 <p> Make boost::atomic behave as C++11 concerning constexpr and noexcept. </p> <p> In particular </p> <pre class="wiki">atomic() noexcept = default; constexpr atomic(T) noexcept; </pre><p> Note that the constructor from T is not explicit. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8057 Trac 1.4.3 viboes Wed, 13 Feb 2013 23:30:21 GMT summary changed https://svn.boost.org/trac10/ticket/8057#comment:1 https://svn.boost.org/trac10/ticket/8057#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">Add constexpre + noexcept fro atomic</span> → <span class="trac-field-new">Add constexpr + noexcept fro atomic</span> </li> </ul> Ticket viboes Thu, 14 Feb 2013 06:37:39 GMT summary changed https://svn.boost.org/trac10/ticket/8057#comment:2 https://svn.boost.org/trac10/ticket/8057#comment:2 <ul> <li><strong>summary</strong> <span class="trac-field-old">Add constexpr + noexcept fro atomic</span> → <span class="trac-field-new">Add constexpr + noexcept for atomic</span> </li> </ul> Ticket timblechmann Thu, 14 Feb 2013 10:15:01 GMT milestone changed https://svn.boost.org/trac10/ticket/8057#comment:3 https://svn.boost.org/trac10/ticket/8057#comment:3 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.54.0</span> </li> </ul> <p> hm, seems that the codebase will require some refactoring to match the c++11 API. will have a look, but it might take me some time. </p> Ticket viboes Thu, 14 Feb 2013 17:59:10 GMT <link>https://svn.boost.org/trac10/ticket/8057#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8057#comment:4</guid> <description> <p> Hi, </p> <p> The following patch worked for me. </p> <pre class="wiki">svn diff boost/atomic Index: boost/atomic/detail/base.hpp =================================================================== --- boost/atomic/detail/base.hpp (revision 82860) +++ boost/atomic/detail/base.hpp (working copy) @@ -143,7 +143,7 @@ typedef T value_type; typedef lockpool::scoped_lock guard_type; public: - base_atomic(void) {} + BOOST_CONSTEXPR base_atomic(void) {} explicit base_atomic(const value_type &amp; v) { @@ -230,8 +230,8 @@ typedef T difference_type; typedef lockpool::scoped_lock guard_type; public: - explicit base_atomic(value_type v) : v_(v) {} - base_atomic(void) {} + explicit BOOST_CONSTEXPR base_atomic(value_type v) : v_(v) {} + BOOST_CONSTEXPR base_atomic(void) {} void store(value_type v, memory_order /*order*/ = memory_order_seq_cst) volatile Index: boost/atomic/atomic.hpp =================================================================== --- boost/atomic/atomic.hpp (revision 82860) +++ boost/atomic/atomic.hpp (working copy) @@ -88,8 +88,8 @@ typedef T value_type; typedef atomics::detail::base_atomic&lt;T, typename atomics::detail::classify&lt;T&gt;::type, atomics::detail::storage_size_of&lt;T&gt;::value, boost::is_signed&lt;T&gt;::value &gt; super; public: - atomic(void) : super() {} - explicit atomic(const value_type &amp; v) : super(v) {} + BOOST_CONSTEXPR atomic(void) : super() {} + explicit BOOST_CONSTEXPR atomic(const value_type &amp; v) : super(v) {} atomic &amp; operator=(value_type v) volatile { </pre><p> But I suspect that we need to specialize boost::atomic&lt;integral&gt;. </p> <p> BTW, why the construtor needs a memcpy? </p> <pre class="wiki"> explicit base_atomic(const value_type &amp; v) { memcpy(&amp;v_, &amp;v, sizeof(value_type)); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>timblechmann</dc:creator> <pubDate>Thu, 14 Feb 2013 18:15:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8057#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8057#comment:5</guid> <description> <p> i've started working on a patch, but i'm not sure how complete it is. </p> <ul><li>not sure about keeping the explicit. according to the standard, there is no explicit ctor. </li><li>also the standard says: 'call by value', not 'call by const-reference' </li><li>regarding the memcpy, i think it is better to cast to the storage type and let the compiler do the copying. memcpy might be slightly better as it probably has relaxed aliasing constraints (not sure if the compiler is smart enough that object and member are different objects). why memcpy was used in the first place, no idea ... the original author might know </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 14 Feb 2013 21:30:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8057#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8057#comment:6</guid> <description> <p> Sorry, the preceding patch didn't worked at all. See attached patch that works for </p> <pre class="wiki">static BOOST_CONSTEXPR boost::atomic&lt;int&gt; x(1); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 14 Feb 2013 21:31:27 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/8057 https://svn.boost.org/trac10/ticket/8057 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">8057.patch</span> </li> </ul> Ticket viboes Thu, 14 Feb 2013 21:48:15 GMT <link>https://svn.boost.org/trac10/ticket/8057#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8057#comment:7</guid> <description> <p> Thanks for the change <a class="changeset" href="https://svn.boost.org/trac10/changeset/82870" title="atomic: adapt for constexpr and noexcept Signed-off-by: Tim Blechmann ...">[82870]</a> :) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 23 Feb 2013 15:10:31 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/8057#comment:8 https://svn.boost.org/trac10/ticket/8057#comment:8 <ul> <li><strong>cc</strong> <span class="trac-author">Andrey.Semashev@…</span> added </li> </ul> <p> The memcpy is needed when the value type is a struct. The struct size may not match exactly the storage_type (e.g. struct s { char a[ 3 ]; };), so we have to zero-initialize the storage first and then copy the struct into it with memcpy. This also takes care of the alignment issue as a side effect. </p> Ticket Andrey Semashev Sat, 17 May 2014 16:14:00 GMT <link>https://svn.boost.org/trac10/ticket/8057#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8057#comment:9</guid> <description> <p> Should we close this ticket? In the latest library version everything is marked noexcept and constexpr (except for user-defined types and pointers). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Mon, 17 Aug 2015 20:32:57 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8057#comment:10 https://svn.boost.org/trac10/ticket/8057#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket