Boost logo

Boost :

Subject: Re: [boost] [utility] Any interest for a macro which automatically creates default move-semantics, comparisson etc for a class
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2013-11-07 08:05:44

2013/11/7 Viktor Sehr <viktor.sehr_at_[hidden]>

> Thanks for the response, I've updated the class to utilize boost::swap,
> boost::move and also marked move\swap function as noexcept.

Marking methods with BOOST_NOEXCEPT by default is not the right way.
noexcept specification depends on types that are stored in class, so
noexcept specification of methods must be detected using TypeTraits and
other magic. Something like this:
 BOOST_NOEXCEPT_IF(/*some expression to detect that operations for type 1
won't throw, like `boost::is_nothrow_move_constructible<Type1>::value`*/ &&
/*same stuff for all other types*/ )

This is a lot of work to do... But it is not critical at the moment.

Following issues must be solved before the macro could be officially
reviewed by community:
* Header DefaultEverything.h requires include guards, hpp extension and
must be lower-case.
* DEFAULT_EVERYTHING does not creates a copy constructor.
* There are some policies that must be followed: For example all the
macro must have BOOST_ prefix and so on.
* tests must be provided

I'm thinking about extending it for pod-classes (only provide
> comparisson\sort) and perhaps move-only classes. Also perhaps a constructor
> which takes all member variables as parameters (especially in the pod-case
> it's probably useful)?

Sounds not bad.

I'd also like to have a macro that generates move assignment and assignment
operators using member swap and constructors. Something like the following:

classname& operator=(BOOST_COPY_ASSIGN_REF(classname) other) \
     BOOST_NOEXCEPT_IF(boost::is_nothrow_constructible<classname>::value \
        && boost::is_nothrow_member_swappable<classname>::value) \
{ \
    classname(other).swap(*this); \
    return *this; \
} \
classname& operator=(BOOST_RV_REF(classname) other) \

BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible<classname>::value \
        && boost::is_nothrow_member_swappable<classname>::value) \
{ \
    classname(boost::move(other)).swap(*this); \
    return *this; \
} \

Best regards,
Antony Polukhin

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