mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-25 18:17:29 +02:00
Compare commits
36 Commits
svn-branch
...
boost-1.43
Author | SHA1 | Date | |
---|---|---|---|
11addaae20 | |||
95555f3f20 | |||
0f33972fe9 | |||
a0733ce5ee | |||
dc8225a7aa | |||
994b37e4d5 | |||
3f4d3eb887 | |||
cda74605fc | |||
b605617c4f | |||
b22e2b64da | |||
46fc256c2f | |||
7615b492af | |||
e0a17b552c | |||
2e805be6df | |||
2f8b91828b | |||
ea5ea7f001 | |||
df633002dd | |||
d726756148 | |||
efcab8aae4 | |||
5dff610007 | |||
d004046aa5 | |||
a046e43990 | |||
b1ebdd60a6 | |||
0b58f052b3 | |||
36736edec5 | |||
57725cb393 | |||
099deb4385 | |||
d150ba8498 | |||
df2abdab6b | |||
780b8bc1b0 | |||
813930aee6 | |||
9e8d8b1871 | |||
4a29dd2a7c | |||
7bd2fd716d | |||
d57e8cfe9e | |||
ed9cb87ac3 |
105
include/boost/fusion/adapted/class/class_iterator.hpp
Normal file
105
include/boost/fusion/adapted/class/class_iterator.hpp
Normal file
@ -0,0 +1,105 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(FUSION_CLASS_ITERATOR_OCTOBER_4_2009_839M)
|
||||
#define FUSION_CLASS_ITERATOR_OCTOBER_4_2009_839M
|
||||
|
||||
#include <boost/fusion/iterator/iterator_facade.hpp>
|
||||
#include <boost/fusion/adapted/class/extension.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/add_reference.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/mpl/minus.hpp>
|
||||
#include <boost/config/no_tr1/utility.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct random_access_traversal_tag;
|
||||
|
||||
template <typename Class, int N_>
|
||||
struct class_iterator
|
||||
: iterator_facade<class_iterator<Class, N_>, random_access_traversal_tag>
|
||||
{
|
||||
BOOST_MPL_ASSERT_RELATION(N_, >=, 0);
|
||||
BOOST_MPL_ASSERT_RELATION(N_, <=, extension::class_size<Class>::value);
|
||||
|
||||
typedef mpl::int_<N_> index;
|
||||
typedef Class class_type;
|
||||
|
||||
class_iterator(Class& class_)
|
||||
: class_(class_) {}
|
||||
Class& class_;
|
||||
|
||||
template <typename Iterator>
|
||||
struct value_of
|
||||
: extension::class_member<Class, N_>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
struct deref
|
||||
{
|
||||
typedef typename
|
||||
mpl::if_<
|
||||
is_const<Class>
|
||||
, typename extension::class_member<Class, N_>::get_type
|
||||
, typename extension::class_member<Class, N_>::proxy
|
||||
>::type
|
||||
type;
|
||||
|
||||
static type
|
||||
call(Iterator const& iter)
|
||||
{
|
||||
return extension::class_member<Class, N_>::
|
||||
call(iter.class_);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator, typename N>
|
||||
struct advance
|
||||
{
|
||||
typedef typename Iterator::index index;
|
||||
typedef typename Iterator::class_type class_type;
|
||||
typedef class_iterator<class_type, index::value + N::value> type;
|
||||
|
||||
static type
|
||||
call(Iterator const& iter)
|
||||
{
|
||||
return type(iter.class_);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
struct next : advance<Iterator, mpl::int_<1> > {};
|
||||
|
||||
template <typename Iterator>
|
||||
struct prior : advance<Iterator, mpl::int_<-1> > {};
|
||||
|
||||
template <typename I1, typename I2>
|
||||
struct distance : mpl::minus<typename I2::index, typename I1::index>
|
||||
{
|
||||
typedef typename
|
||||
mpl::minus<
|
||||
typename I2::index, typename I1::index
|
||||
>::type
|
||||
type;
|
||||
|
||||
static type
|
||||
call(I1 const&, I2 const&)
|
||||
{
|
||||
return type();
|
||||
}
|
||||
};
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
70
include/boost/fusion/adapted/class/detail/at_impl.hpp
Normal file
70
include/boost/fusion/adapted/class/detail/at_impl.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_AT_IMPL_OCTOBER_4_2009_920PM)
|
||||
#define BOOST_FUSION_AT_IMPL_OCTOBER_4_2009_920PM
|
||||
|
||||
#include <boost/fusion/support/detail/access.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct at_impl;
|
||||
|
||||
template <typename Class, int N>
|
||||
struct class_member;
|
||||
|
||||
template <typename Class>
|
||||
struct class_size;
|
||||
|
||||
template <>
|
||||
struct at_impl<class_tag>
|
||||
{
|
||||
template <typename Sequence, typename N>
|
||||
struct apply
|
||||
{
|
||||
static int const n_value = N::value;
|
||||
BOOST_MPL_ASSERT_RELATION(
|
||||
n_value, <=, extension::class_size<Sequence>::value);
|
||||
|
||||
typedef typename
|
||||
extension::class_member<Sequence, N::value>
|
||||
element;
|
||||
|
||||
typedef typename
|
||||
mpl::if_<
|
||||
is_const<Sequence>
|
||||
, typename class_member<Sequence, N::value>::get_type
|
||||
, typename class_member<Sequence, N::value>::proxy
|
||||
>::type
|
||||
type;
|
||||
|
||||
static type
|
||||
call(Sequence& seq)
|
||||
{
|
||||
return extension::
|
||||
class_member<Sequence, N::value>::call(seq);
|
||||
}
|
||||
|
||||
//~ static typename class_member<Sequence, N::value>::get_type
|
||||
//~ call(Sequence const& seq)
|
||||
//~ {
|
||||
//~ return extension::
|
||||
//~ class_member<Sequence, N::value>::call(seq);
|
||||
//~ }
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
54
include/boost/fusion/adapted/class/detail/at_key_impl.hpp
Normal file
54
include/boost/fusion/adapted/class/detail/at_key_impl.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2007 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_AT_KEY_IMPL_OCTOBER_4_2009_920PM)
|
||||
#define BOOST_FUSION_AT_KEY_IMPL_OCTOBER_4_2009_920PM
|
||||
|
||||
#include <boost/fusion/support/detail/access.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct at_key_impl;
|
||||
|
||||
template <typename Class, typename Key>
|
||||
struct class_assoc_member;
|
||||
|
||||
template <>
|
||||
struct at_key_impl<class_tag>
|
||||
{
|
||||
template <typename Sequence, typename Key>
|
||||
struct apply
|
||||
{
|
||||
typedef typename
|
||||
extension::class_assoc_member<Sequence, Key>
|
||||
element;
|
||||
|
||||
typedef typename
|
||||
mpl::eval_if<
|
||||
is_const<Sequence>
|
||||
, detail::cref_result<element>
|
||||
, detail::ref_result<element>
|
||||
>::type
|
||||
type;
|
||||
|
||||
static type
|
||||
call(Sequence& seq)
|
||||
{
|
||||
return extension::
|
||||
class_assoc_member<Sequence, Key>::call(seq);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
40
include/boost/fusion/adapted/class/detail/begin_impl.hpp
Normal file
40
include/boost/fusion/adapted/class/detail/begin_impl.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_BEGIN_IMPL_OCTOBER_4_2009_920PM)
|
||||
#define BOOST_FUSION_BEGIN_IMPL_OCTOBER_4_2009_920PM
|
||||
|
||||
#include <boost/fusion/adapted/class/class_iterator.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct begin_impl;
|
||||
|
||||
template <>
|
||||
struct begin_impl<class_tag>
|
||||
{
|
||||
template <typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef class_iterator<Sequence, 0> type;
|
||||
|
||||
static type
|
||||
call(Sequence& v)
|
||||
{
|
||||
return type(v);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -0,0 +1,35 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_CATEGORY_OF_IMPL_OCTOBER_4_2009_919PM)
|
||||
#define BOOST_FUSION_CATEGORY_OF_IMPL_OCTOBER_4_2009_919PM
|
||||
|
||||
#include <boost/config/no_tr1/utility.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
struct random_access_traversal_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct category_of_impl;
|
||||
|
||||
template<>
|
||||
struct category_of_impl<class_tag>
|
||||
{
|
||||
template<typename T>
|
||||
struct apply
|
||||
{
|
||||
typedef random_access_traversal_tag type;
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
48
include/boost/fusion/adapted/class/detail/end_impl.hpp
Normal file
48
include/boost/fusion/adapted/class/detail/end_impl.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_END_IMPL_OCTOBER_4_2009_919PM)
|
||||
#define BOOST_FUSION_END_IMPL_OCTOBER_4_2009_919PM
|
||||
|
||||
#include <boost/fusion/adapted/class/class_iterator.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template <typename Tag>
|
||||
struct end_impl;
|
||||
|
||||
template <typename Class>
|
||||
struct class_size;
|
||||
|
||||
template <>
|
||||
struct end_impl<class_tag>
|
||||
{
|
||||
template <typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef
|
||||
class_iterator<
|
||||
Sequence
|
||||
, class_size<Sequence>::value
|
||||
>
|
||||
type;
|
||||
|
||||
static type
|
||||
call(Sequence& v)
|
||||
{
|
||||
return type(v);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
40
include/boost/fusion/adapted/class/detail/has_key_impl.hpp
Normal file
40
include/boost/fusion/adapted/class/detail/has_key_impl.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2007 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_HAS_KEY_IMPL_OCTOBER_4_2009_919PM)
|
||||
#define BOOST_FUSION_HAS_KEY_IMPL_OCTOBER_4_2009_919PM
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
|
||||
namespace boost { namespace fusion {
|
||||
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
struct no_such_member;
|
||||
|
||||
template<typename T>
|
||||
struct has_key_impl;
|
||||
|
||||
template<typename Class, typename Key>
|
||||
struct class_assoc_member;
|
||||
|
||||
template<>
|
||||
struct has_key_impl<class_tag>
|
||||
{
|
||||
template<typename Sequence, typename Key>
|
||||
struct apply
|
||||
: mpl::not_<is_same<no_such_member, typename class_assoc_member<Sequence, Key>::type> >
|
||||
{
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -0,0 +1,31 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_IS_SEQUENCE_IMPL_OCTOBER_4_2009_919PM)
|
||||
#define BOOST_FUSION_IS_SEQUENCE_IMPL_OCTOBER_4_2009_919PM
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename Tag>
|
||||
struct is_sequence_impl;
|
||||
|
||||
template<>
|
||||
struct is_sequence_impl<class_tag>
|
||||
{
|
||||
template<typename Sequence>
|
||||
struct apply : mpl::true_ {};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
32
include/boost/fusion/adapted/class/detail/is_view_impl.hpp
Normal file
32
include/boost/fusion/adapted/class/detail/is_view_impl.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_IS_VIEW_IMPL_OCTOBER_4_2009_919PM)
|
||||
#define BOOST_FUSION_IS_VIEW_IMPL_OCTOBER_4_2009_919PM
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename Tag>
|
||||
struct is_view_impl;
|
||||
|
||||
template<>
|
||||
struct is_view_impl<class_tag>
|
||||
{
|
||||
template<typename T>
|
||||
struct apply : mpl::false_
|
||||
{};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
37
include/boost/fusion/adapted/class/detail/size_impl.hpp
Normal file
37
include/boost/fusion/adapted/class/detail/size_impl.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_SIZE_IMPL_OCTOBER_4_2009_919PM)
|
||||
#define BOOST_FUSION_SIZE_IMPL_OCTOBER_4_2009_919PM
|
||||
|
||||
#include <boost/mpl/int.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
namespace extension
|
||||
{
|
||||
template <typename Class>
|
||||
struct class_size;
|
||||
}
|
||||
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct size_impl;
|
||||
|
||||
template <>
|
||||
struct size_impl<class_tag>
|
||||
{
|
||||
template <typename Sequence>
|
||||
struct apply : extension::class_size<Sequence> {};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
47
include/boost/fusion/adapted/class/detail/value_at_impl.hpp
Normal file
47
include/boost/fusion/adapted/class/detail/value_at_impl.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_VALUE_AT_IMPL_OCTOBER_4_2009_918PM)
|
||||
#define BOOST_FUSION_VALUE_AT_IMPL_OCTOBER_4_2009_918PM
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct value_at_impl;
|
||||
|
||||
template <typename Class, int N>
|
||||
struct class_member;
|
||||
|
||||
template <typename Class>
|
||||
struct class_size;
|
||||
|
||||
template <>
|
||||
struct value_at_impl<class_tag>
|
||||
{
|
||||
template <typename Sequence, typename N>
|
||||
struct apply
|
||||
{
|
||||
static int const n_value = N::value;
|
||||
BOOST_MPL_ASSERT_RELATION(
|
||||
n_value, <=, extension::class_size<Sequence>::value);
|
||||
|
||||
typedef typename
|
||||
extension::class_member<Sequence, N::value>::type
|
||||
type;
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -0,0 +1,39 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2007 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(BOOST_FUSION_VALUE_AT_KEY_IMPL_OCTOBER_4_2009_918PM)
|
||||
#define BOOST_FUSION_VALUE_AT_KEY_IMPL_OCTOBER_4_2009_918PM
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct class_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct value_at_key_impl;
|
||||
|
||||
template <typename Class, typename Key>
|
||||
struct class_assoc_member;
|
||||
|
||||
template <>
|
||||
struct value_at_key_impl<class_tag>
|
||||
{
|
||||
template <typename Sequence, typename Key>
|
||||
struct apply
|
||||
{
|
||||
typedef typename
|
||||
extension::class_assoc_member<Sequence, Key>::type
|
||||
type;
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
68
include/boost/fusion/adapted/class/extension.hpp
Normal file
68
include/boost/fusion/adapted/class/extension.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(FUSION_CLASS_EXTENSION_OCTOBER_4_2009_839PM)
|
||||
#define FUSION_CLASS_EXTENSION_OCTOBER_4_2009_839PM
|
||||
|
||||
#include <boost/type_traits/add_const.hpp>
|
||||
|
||||
namespace boost { namespace fusion { namespace extension
|
||||
{
|
||||
template <typename Class, int N>
|
||||
struct class_member;
|
||||
|
||||
template <typename Class>
|
||||
struct class_size;
|
||||
|
||||
template <typename Class, int N>
|
||||
struct class_member<Class const, N> : class_member<Class, N> {};
|
||||
//~ {
|
||||
//~ typedef typename class_member<Class, N>::type type;
|
||||
//~ typedef typename class_member<Class, N>::get_type get_type;
|
||||
//~ typedef typename class_member<Class, N>::proxy proxy;
|
||||
|
||||
//~ static get_type&
|
||||
//~ call(Class const& class_)
|
||||
//~ {
|
||||
//~ return class_member<Class, N>::call(
|
||||
//~ const_cast<Class&>(class_));
|
||||
//~ }
|
||||
//~ };
|
||||
|
||||
template <typename Class>
|
||||
struct class_size<Class const>
|
||||
: class_size<Class>
|
||||
{};
|
||||
|
||||
struct no_such_member;
|
||||
|
||||
template<typename Class, typename Key>
|
||||
struct class_assoc_member
|
||||
{
|
||||
typedef no_such_member type;
|
||||
};
|
||||
|
||||
template<typename Class, typename Key>
|
||||
struct class_assoc_member<Class const, Key>
|
||||
{
|
||||
typedef typename
|
||||
add_const<typename class_assoc_member<Class, Key>::type>::type
|
||||
type;
|
||||
|
||||
static type&
|
||||
call(Class const& class_)
|
||||
{
|
||||
return class_assoc_member<Class, Key>::call(
|
||||
const_cast<Class&>(class_));
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace boost { namespace fusion
|
||||
|
||||
template <typename Sequence>
|
||||
vector(Sequence const& rhs)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
|
||||
: vec(ctor_helper(rhs, is_base_of<vector, Sequence>())) {}
|
||||
#else
|
||||
: vec(rhs) {}
|
||||
@ -129,7 +129,7 @@ namespace boost { namespace fusion
|
||||
|
||||
private:
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1500)
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1600)
|
||||
static vector_n const&
|
||||
ctor_helper(vector const& rhs, mpl::true_)
|
||||
{
|
||||
|
124
test/functional/make_unfused_generic.cpp
Normal file
124
test/functional/make_unfused_generic.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006-2007 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/fusion/functional/generation/make_unfused_generic.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
namespace fusion = boost::fusion;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
using boost::noncopyable;
|
||||
typedef mpl::true_ no_nullary_call;
|
||||
|
||||
using boost::ref;
|
||||
using boost::cref;
|
||||
|
||||
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, class Seq>
|
||||
struct result< Self(Seq &) >
|
||||
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||
boost::blank, mpl::identity<long> >::type
|
||||
{ };
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq) const
|
||||
{
|
||||
long state = 0;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
template < typename Seq >
|
||||
long operator()(Seq const & seq)
|
||||
{
|
||||
long state = 100;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
struct fold_op
|
||||
{
|
||||
typedef long result_type;
|
||||
|
||||
template <typename T>
|
||||
long operator()(T const & elem, long value) const
|
||||
{
|
||||
return value + sizeof(T) * elem;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
long operator()(T & elem, long value) const
|
||||
{
|
||||
elem += sizeof(T);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline T const & const_(T const & t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_func<> f;
|
||||
test_func<noncopyable> f_nc;
|
||||
|
||||
fusion::result_of::make_unfused_generic< test_func<> >::type unfused_func =
|
||||
fusion::make_unfused_generic(f);
|
||||
|
||||
fusion::result_of::make_unfused_generic< boost::reference_wrapper<
|
||||
test_func<noncopyable> > >::type unfused_func_ref =
|
||||
fusion::make_unfused_generic(ref(f_nc));
|
||||
|
||||
fusion::result_of::make_unfused_generic< boost::reference_wrapper<
|
||||
test_func<noncopyable> const> >::type unfused_func_c_ref =
|
||||
fusion::make_unfused_generic(cref(f_nc));
|
||||
|
||||
BOOST_TEST(unfused_func() == 100);
|
||||
BOOST_TEST(const_(unfused_func)() == 0);
|
||||
BOOST_TEST(unfused_func_ref() == 100);
|
||||
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||
|
||||
long lvalue = 12;
|
||||
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||
BOOST_TEST(unfused_func(lvalue,lvalue,1,2l,'\007') == 100 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 2*sizeof(long));
|
||||
BOOST_TEST(const_(unfused_func)(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 4*sizeof(long));
|
||||
BOOST_TEST(unfused_func_ref(lvalue,lvalue,1,2l,'\007') == 100 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 6*sizeof(long));
|
||||
BOOST_TEST(unfused_func_c_ref(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 8*sizeof(long));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
126
test/functional/make_unfused_lvalue_args.cpp
Normal file
126
test/functional/make_unfused_lvalue_args.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006-2007 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/fusion/functional/generation/make_unfused_lvalue_args.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
namespace fusion = boost::fusion;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
using boost::noncopyable;
|
||||
typedef mpl::true_ no_nullary_call;
|
||||
|
||||
using boost::ref;
|
||||
using boost::cref;
|
||||
|
||||
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, class Seq>
|
||||
struct result< Self(Seq &) >
|
||||
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||
boost::blank, mpl::identity<long> >::type
|
||||
{ };
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq) const
|
||||
{
|
||||
long state = 0;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
template < typename Seq >
|
||||
long operator()(Seq const & seq)
|
||||
{
|
||||
long state = 100;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
struct fold_op
|
||||
{
|
||||
typedef long result_type;
|
||||
|
||||
template <typename T>
|
||||
long operator()(T & elem, long value) const
|
||||
{
|
||||
elem += sizeof(T);
|
||||
return value + elem;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline T const & const_(T const & t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_func<> f;
|
||||
test_func<noncopyable> f_nc;
|
||||
|
||||
fusion::result_of::make_unfused_lvalue_args< test_func<> >::type unfused_func =
|
||||
fusion::make_unfused_lvalue_args(f);
|
||||
|
||||
fusion::result_of::make_unfused_lvalue_args< boost::reference_wrapper<
|
||||
test_func<noncopyable> > >::type unfused_func_ref =
|
||||
fusion::make_unfused_lvalue_args(ref(f_nc));
|
||||
|
||||
fusion::result_of::make_unfused_lvalue_args< boost::reference_wrapper<
|
||||
test_func<noncopyable> const> >::type unfused_func_c_ref =
|
||||
fusion::make_unfused_lvalue_args(cref(f_nc));
|
||||
|
||||
BOOST_TEST(unfused_func() == 100);
|
||||
BOOST_TEST(const_(unfused_func)() == 0);
|
||||
BOOST_TEST(unfused_func_ref() == 100);
|
||||
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||
|
||||
long lv1 = 2; int lv2 = 3l; char lv3 = '\007';
|
||||
long expected;
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func(lv1,lv2,lv3) == 100 + expected);
|
||||
BOOST_TEST(lv1 == 2+1*sizeof(lv1) && lv2 == 3+1*sizeof(lv2) && lv3 == 7+1*sizeof(lv3));
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(const_(unfused_func)(lv1,lv2,lv3) == 0 + expected);
|
||||
BOOST_TEST(lv1 == 2+2*sizeof(lv1) && lv2 == 3+2*sizeof(lv2) && lv3 == 7+2*sizeof(lv3));
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func_ref(lv1,lv2,lv3) == 100 + expected);
|
||||
BOOST_TEST(lv1 == 2+3*sizeof(lv1) && lv2 == 3+3*sizeof(lv2) && lv3 == 7+3*sizeof(lv3));
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func_c_ref(lv1,lv2,lv3) == 0 + expected);
|
||||
BOOST_TEST(lv1 == 2+4*sizeof(lv1) && lv2 == 3+4*sizeof(lv2) && lv3 == 7+4*sizeof(lv3));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
110
test/functional/make_unfused_rvalue_args.cpp
Normal file
110
test/functional/make_unfused_rvalue_args.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006-2007 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/fusion/functional/generation/make_unfused_rvalue_args.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
namespace fusion = boost::fusion;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
using boost::noncopyable;
|
||||
typedef mpl::true_ no_nullary_call;
|
||||
|
||||
using boost::ref;
|
||||
using boost::cref;
|
||||
|
||||
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, class Seq>
|
||||
struct result< Self(Seq &) >
|
||||
: mpl::if_< mpl::and_< fusion::result_of::empty<Seq>, RemoveNullary >,
|
||||
boost::blank, mpl::identity<long> >::type
|
||||
{ };
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq) const
|
||||
{
|
||||
long state = 0;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
template < typename Seq >
|
||||
long operator()(Seq const & seq)
|
||||
{
|
||||
long state = 100;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
struct fold_op
|
||||
{
|
||||
typedef long result_type;
|
||||
|
||||
template <typename T>
|
||||
long operator()(T const & elem, long value) const
|
||||
{
|
||||
return value + sizeof(T) * elem;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline T const & const_(T const & t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_func<> f;
|
||||
test_func<noncopyable> f_nc;
|
||||
|
||||
fusion::result_of::make_unfused_rvalue_args< test_func<> >::type unfused_func =
|
||||
fusion::make_unfused_rvalue_args(f);
|
||||
|
||||
fusion::result_of::make_unfused_rvalue_args< boost::reference_wrapper<
|
||||
test_func<noncopyable> > >::type unfused_func_ref =
|
||||
fusion::make_unfused_rvalue_args(ref(f_nc));
|
||||
|
||||
fusion::result_of::make_unfused_rvalue_args< boost::reference_wrapper<
|
||||
test_func<noncopyable> const> >::type unfused_func_c_ref =
|
||||
fusion::make_unfused_rvalue_args(cref(f_nc));
|
||||
|
||||
BOOST_TEST(unfused_func() == 100);
|
||||
BOOST_TEST(const_(unfused_func)() == 0);
|
||||
BOOST_TEST(unfused_func_ref() == 100);
|
||||
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||
|
||||
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||
BOOST_TEST(unfused_func(1,2l,'\007') == 100 + expected);
|
||||
BOOST_TEST(const_(unfused_func)(1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(unfused_func_ref(1,2l,'\007') == 100 + expected);
|
||||
BOOST_TEST(unfused_func_c_ref(1,2l,'\007') == 0 + expected);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
126
test/functional/unfused_generic.cpp
Normal file
126
test/functional/unfused_generic.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006-2007 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/fusion/functional/adapter/unfused_generic.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
|
||||
namespace fusion = boost::fusion;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
using boost::noncopyable;
|
||||
typedef mpl::true_ no_nullary_call;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, class Seq>
|
||||
struct result< Self (Seq) >
|
||||
: mpl::identity<long>
|
||||
{ };
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq) const
|
||||
{
|
||||
long state = 0;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq)
|
||||
{
|
||||
long state = 100;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
struct fold_op
|
||||
{
|
||||
template <typename T>
|
||||
long operator()(T const & elem, long value) const
|
||||
{
|
||||
return value + sizeof(T) * elem;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
long operator()(T & elem, long value) const
|
||||
{
|
||||
elem += sizeof(T);
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, typename T0, typename T1> struct result< Self(T0,T1) >
|
||||
: mpl::identity<long>
|
||||
{ };
|
||||
};
|
||||
};
|
||||
|
||||
void result_type_tests()
|
||||
{
|
||||
using boost::is_same;
|
||||
|
||||
typedef fusion::unfused_generic< test_func<> > t;
|
||||
BOOST_TEST(( is_same< boost::result_of< t () >::type, long >::value ));
|
||||
BOOST_TEST(( is_same< boost::result_of< t (int) >::type, long >::value ));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
result_type_tests();
|
||||
|
||||
test_func<noncopyable> f;
|
||||
fusion::unfused_generic< test_func<> > unfused_func;
|
||||
fusion::unfused_generic< test_func<noncopyable> & > unfused_func_ref(f);
|
||||
fusion::unfused_generic< test_func<> const > unfused_func_c;
|
||||
fusion::unfused_generic< test_func<> > const unfused_func_c2;
|
||||
fusion::unfused_generic< test_func<noncopyable> const & > unfused_func_c_ref(f);
|
||||
|
||||
BOOST_TEST(unfused_func() == 100);
|
||||
BOOST_TEST(unfused_func_ref() == 100);
|
||||
BOOST_TEST(unfused_func_c() == 0);
|
||||
BOOST_TEST(unfused_func_c2() == 0);
|
||||
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||
|
||||
long lvalue = 12;
|
||||
// also test const lvalues to pick up compiler deficiencies in that area
|
||||
int const clvalue_1 = 1;
|
||||
long const clvalue_2 = 2;
|
||||
|
||||
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||
BOOST_TEST(unfused_func(lvalue,lvalue,clvalue_1,clvalue_2,'\007') == 100 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 2*sizeof(long));
|
||||
BOOST_TEST(unfused_func_ref(lvalue,lvalue,1,2l,'\007') == 100 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 4*sizeof(long));
|
||||
BOOST_TEST(unfused_func_c(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 6*sizeof(long));
|
||||
BOOST_TEST(unfused_func_c2(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 8*sizeof(long));
|
||||
BOOST_TEST(unfused_func_c_ref(lvalue,lvalue,1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(lvalue == 12 + 10*sizeof(long));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
119
test/functional/unfused_lvalue_args.cpp
Normal file
119
test/functional/unfused_lvalue_args.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006-2007 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/fusion/functional/adapter/unfused_lvalue_args.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
|
||||
namespace fusion = boost::fusion;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
using boost::noncopyable;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, class Seq>
|
||||
struct result< Self(Seq) >
|
||||
: mpl::identity<long>
|
||||
{ };
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq) const
|
||||
{
|
||||
long state = 0;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq)
|
||||
{
|
||||
long state = 100;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
struct fold_op
|
||||
{
|
||||
typedef long result_type;
|
||||
|
||||
template <typename T>
|
||||
long operator()(T & elem, long value) const
|
||||
{
|
||||
elem += sizeof(T);
|
||||
return value + elem;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
void result_type_tests()
|
||||
{
|
||||
using boost::is_same;
|
||||
|
||||
typedef fusion::unfused_lvalue_args< test_func<> > t;
|
||||
BOOST_TEST(( is_same< boost::result_of< t () >::type, long >::value ));
|
||||
BOOST_TEST(( is_same< boost::result_of< t (int) >::type, long >::value ));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
result_type_tests();
|
||||
|
||||
test_func<noncopyable> f;
|
||||
fusion::unfused_lvalue_args< test_func<> > unfused_func;
|
||||
fusion::unfused_lvalue_args< test_func<noncopyable> & > unfused_func_ref(f);
|
||||
fusion::unfused_lvalue_args< test_func<> const > unfused_func_c;
|
||||
fusion::unfused_lvalue_args< test_func<> > const unfused_func_c2;
|
||||
fusion::unfused_lvalue_args< test_func<noncopyable> const & > unfused_func_c_ref(f);
|
||||
|
||||
BOOST_TEST(unfused_func() == 100);
|
||||
BOOST_TEST(unfused_func_ref() == 100);
|
||||
BOOST_TEST(unfused_func_c() == 0);
|
||||
BOOST_TEST(unfused_func_c2() == 0);
|
||||
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||
|
||||
long lv1 = 2; int lv2 = 3l; char lv3 = '\007';
|
||||
long expected;
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func(lv1,lv2,lv3) == 100 + expected);
|
||||
BOOST_TEST(lv1 == 2+1*sizeof(lv1) && lv2 == 3+1*sizeof(lv2) && lv3 == 7+1*sizeof(lv3));
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func_ref(lv1,lv2,lv3) == 100 + expected);
|
||||
BOOST_TEST(lv1 == 2+2*sizeof(lv1) && lv2 == 3+2*sizeof(lv2) && lv3 == 7+2*sizeof(lv3));
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func_c(lv1,lv2,lv3) == 0 + expected);
|
||||
BOOST_TEST(lv1 == 2+3*sizeof(lv1) && lv2 == 3+3*sizeof(lv2) && lv3 == 7+3*sizeof(lv3));
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func_c2(lv1,lv2,lv3) == 0 + expected);
|
||||
BOOST_TEST(lv1 == 2+4*sizeof(lv1) && lv2 == 3+4*sizeof(lv2) && lv3 == 7+4*sizeof(lv3));
|
||||
|
||||
expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3);
|
||||
BOOST_TEST(unfused_func_c_ref(lv1,lv2,lv3) == 0 + expected);
|
||||
BOOST_TEST(lv1 == 2+5*sizeof(lv1) && lv2 == 3+5*sizeof(lv2) && lv3 == 7+5*sizeof(lv3));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
102
test/functional/unfused_rvalue_args.cpp
Normal file
102
test/functional/unfused_rvalue_args.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2006-2007 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/fusion/functional/adapter/unfused_rvalue_args.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
|
||||
namespace fusion = boost::fusion;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
using boost::noncopyable;
|
||||
typedef mpl::true_ no_nullary_call;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, class Seq>
|
||||
struct result< Self(Seq) >
|
||||
: mpl::identity<long>
|
||||
{ };
|
||||
|
||||
template <typename Seq>
|
||||
long operator()(Seq const & seq) const
|
||||
{
|
||||
long state = 0;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
template < typename Seq >
|
||||
long operator()(Seq const & seq)
|
||||
{
|
||||
long state = 100;
|
||||
return fusion::fold(seq, state, fold_op());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
struct fold_op
|
||||
{
|
||||
typedef long result_type;
|
||||
|
||||
template <typename T>
|
||||
long operator()(T const & elem, long value) const
|
||||
{
|
||||
return value + sizeof(T) * elem;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
void result_type_tests()
|
||||
{
|
||||
using boost::is_same;
|
||||
|
||||
typedef fusion::unfused_rvalue_args< test_func<> > t;
|
||||
BOOST_TEST(( is_same< boost::result_of< t () >::type, long >::value ));
|
||||
BOOST_TEST(( is_same< boost::result_of< t (int) >::type, long >::value ));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
result_type_tests();
|
||||
|
||||
test_func<noncopyable> f;
|
||||
fusion::unfused_rvalue_args< test_func<> > unfused_func;
|
||||
fusion::unfused_rvalue_args< test_func<noncopyable> & > unfused_func_ref(f);
|
||||
fusion::unfused_rvalue_args< test_func<> const > unfused_func_c;
|
||||
fusion::unfused_rvalue_args< test_func<> > const unfused_func_c2;
|
||||
fusion::unfused_rvalue_args< test_func<noncopyable> const & > unfused_func_c_ref(f);
|
||||
|
||||
BOOST_TEST(unfused_func() == 100);
|
||||
BOOST_TEST(unfused_func_ref() == 100);
|
||||
BOOST_TEST(unfused_func_c() == 0);
|
||||
BOOST_TEST(unfused_func_c2() == 0);
|
||||
BOOST_TEST(unfused_func_c_ref() == 0);
|
||||
|
||||
static const long expected = 1*sizeof(int) + 2*sizeof(long) + 7*sizeof(char);
|
||||
BOOST_TEST(unfused_func(1,2l,'\007') == 100 + expected);
|
||||
BOOST_TEST(unfused_func_ref(1,2l,'\007') == 100 + expected);
|
||||
BOOST_TEST(unfused_func_c(1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(unfused_func_c2(1,2l,'\007') == 0 + expected);
|
||||
BOOST_TEST(unfused_func_c_ref(1,2l,'\007') == 0 + expected);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user