|
Boost : |
Subject: Re: [boost] [utility] Any interest for a macro which automatically creates default move-semantics, comparisson etc for a class
From: Bjorn Reese (breese_at_[hidden])
Date: 2013-11-08 09:20:21
On 11/06/2013 06:38 PM, Viktor Sehr wrote:
> Example usage:
> class Foo {
> public:
> Foo() {}
> DEFAULT_EVERYTHING(Foo,
> ( (int)(a) )
> ( (std::vector<int>)(b) )
> ( (float)(c) )
> );
> };
>
> Any interest, suggestions or ideas?
If we are going to specify the member variables in a funny way, it may
be worth considering a solution based on Boost.Fusion. For example,
swap() can be made like this:
class Foo {
public:
Foo()
{
member.a = 0;
member.c = 0.0;
}
// swap and swap_functor should be turned into a macro
public:
void swap(Foo& other)
{
using namespace boost::fusion;
for_each(zip_view< vector2<member_type&, member_type&>
>(vector2<member_type&, member_type&>(member, other.member)),
swap_functor());
}
private:
struct swap_functor
{
template <typename T>
void operator()(const boost::fusion::vector2<T,T>& data) const
{
using namespace boost::fusion;
boost::swap(at_c<0>(data), at_c<1>(data));
}
};
private:
BOOST_FUSION_DEFINE_STRUCT_INLINE
(member_type,
// Member variables
(int, a)
(std::vector<int>, b)
(float, c)
)
member_type member;
};
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk