Boost logo

Boost :

Subject: [boost] Manually marking noexcept for a constructor
From: Daryle Walker (darylew_at_[hidden])
Date: 2012-02-08 13:38:06

I realized that my proposed C++11 update for base_from_member should propagate noexcept.  But how do I manually specify the noexcept status of an inner constructor?  (Beta versions of C++11 may just have core language changes but not the library changes, so I shouldn't rely on is_nothrow_XXX_constructible just like not relying on std::forward.)
I originally thought of:
class MyType{    MyInnerType  x;public:    MyType() noexcept( noexcept(MyInnerType()) );};
This expression includes the inner default constructor call, but it also secretly includes a destructor call (for MyInnerType), and therefore includes it in the calculations!
But how about:
class MyType2{    MyInnerType  x;public:    MyType2() noexcept( noexcept(new (std::nothrow) MyInnerType()) );};
Hopefully this, or something like it, includes the constructor call, without calling a destructor.  I think the C++11 version of nothrow_t-new is marked noexcept, and I hope the complete new call doesn't hide the constructor call.
Daryle W.

Boost list run by bdawes at, gregod at, cpdaniel at, john at