[/============================================================================== Copyright (C) 2001-2011 Joel de Guzman Copyright (C) 2006 Dan Marsden Use, modification and distribution is 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) ===============================================================================/] [section Support] A couple of classes and metafunctions provide basic support for Fusion. [section is_sequence] [heading Description] Metafunction that evaluates to `mpl::true_` if a certain type `T` is a conforming Fusion __sequence__, `mpl::false_` otherwise. This may be specialized to accommodate clients which provide Fusion conforming sequences. [heading Synopsis] namespace traits { template struct is_sequence { typedef __unspecified__ type; }; } [heading Parameters] [table [[Parameter] [Requirement] [Description]] [[`T`] [Any type] [The type to query.]] ] [heading Expression Semantics] typedef traits::is_sequence::type c; [*Return type]: An __mpl_boolean_constant__. [*Semantics]: Metafunction that evaluates to `mpl::true_` if a certain type `T` is a conforming Fusion sequence, `mpl::false_` otherwise. [heading Header] #include #include [heading Example] BOOST_MPL_ASSERT_NOT(( traits::is_sequence< std::vector > )); BOOST_MPL_ASSERT_NOT(( is_sequence< int > )); BOOST_MPL_ASSERT(( traits::is_sequence<__list__<> > )); BOOST_MPL_ASSERT(( traits::is_sequence<__list__ > )); BOOST_MPL_ASSERT(( traits::is_sequence<__vector__<> > )); BOOST_MPL_ASSERT(( traits::is_sequence<__vector__ > )); [endsect] [section is_view] [heading Description] Metafunction that evaluates to `mpl::true_` if a certain type `T` is a conforming Fusion __view__, `mpl::false_` otherwise. A view is a specialized sequence that does not actually contain data. Views hold sequences which may be other views. In general, views are held by other views by value, while non-views are held by other views by reference. `is_view` may be specialized to accommodate clients providing Fusion conforming views. [heading Synopsis] namespace traits { template struct is_view { typedef __unspecified__ type; }; } [heading Parameters] [table [[Parameter] [Requirement] [Description]] [[`T`] [Any type] [The type to query.]] ] [heading Expression Semantics] typedef traits::is_view::type c; [*Return type]: An __mpl_boolean_constant__. [*Semantics]: Metafunction that evaluates to `mpl::true_` if a certain type `T` is a conforming Fusion view, `mpl::false_` otherwise. [heading Header] #include #include [heading Example] BOOST_MPL_ASSERT_NOT(( traits::is_view > )); BOOST_MPL_ASSERT_NOT(( traits::is_view )); using boost::mpl::_ using boost::is_pointer; typedef __vector__ vector_type; typedef __filter_view__ > filter_view_type; BOOST_MPL_ASSERT(( traits::is_view )); [endsect] [section tag_of] [heading Description] All conforming Fusion sequences and iterators have an associated tag type. The purpose of the tag is to enable __tag_dispatching__ from __intrinsic__ functions to implementations appropriate for the type. This metafunction may be specialized to accommodate clients providing Fusion conforming sequences. [heading Synopsis] namespace traits { template struct tag_of { typedef __unspecified__ type; }; } [heading Parameters] [table [[Parameter] [Requirement] [Description]] [[`T`] [Any type] [The type to query.]] ] [heading Expression Semantics] typedef traits::tag_of::type tag; [*Return type]: Any type. [*Semantics]: Returns the tag type associated with `T`. [heading Header] #include #include [heading Example] typedef traits::tag_of<__list__<> >::type tag1; typedef traits::tag_of<__list__ >::type tag2; typedef traits::tag_of<__vector__<> >::type tag3; typedef traits::tag_of<__vector__ >::type tag4; BOOST_MPL_ASSERT((boost::is_same)); BOOST_MPL_ASSERT((boost::is_same)); [endsect] [section category_of] [heading Description] A metafunction that establishes the conceptual classification of a particular __sequence__ or __iterator__ (see __iterator_concepts__ and __sequence_concepts__). [heading Synopsis] namespace traits { template struct category_of { typedef __unspecified__ type; }; } [heading Parameters] [table [[Parameter] [Requirement] [Description]] [[`T`] [Any type] [The type to query.]] ] [heading Expression Semantics] typedef traits::category_of::type category; [*Return type]: The return type is derived from one of: namespace boost { namespace fusion { struct incrementable_traversal_tag {}; struct single_pass_traversal_tag : incrementable_traversal_tag {}; struct forward_traversal_tag : single_pass_traversal_tag {}; struct bidirectional_traversal_tag : forward_traversal_tag {}; struct random_access_traversal_tag : bidirectional_traversal_tag {}; }} And optionally from: namespace boost { namespace fusion { struct associative_tag {}; struct unbounded_tag {}; }} [*Semantics]: Establishes the conceptual classification of a particular __sequence__ or __iterator__. [heading Header] #include #include [heading Example] using boost::is_base_of; typedef traits::category_of<__list__<> >::type list_category; typedef traits::category_of<__vector__<> >::type vector_category; BOOST_MPL_ASSERT(( is_base_of )); BOOST_MPL_ASSERT(( is_base_of )); [endsect] [section deduce] [heading Description] Metafunction to apply __element_conversion__ to the full argument type. It removes references to `const`, references to array types are kept, even if the array is `const`. Reference wrappers are removed (see __note_ref_wrappers__)[footnote Since C++11, the standard reference wrappers are also removed.]. [heading Header] #include #include [heading Synopsis] namespace traits { template struct deduce { typedef __unspecified__ type; }; } [heading Example] template struct holder { typename traits::deduce::type element; holder(T const & a) : element(a) { } }; template holder make_holder(T const & a) { return holder(a); } [heading See also] * __deduce_sequence__ [endsect] [section deduce_sequence] [heading Description] Applies __element_conversion__ to each element in a __forward_sequence__. The resulting type is a __random_access_sequence__ that provides a converting constructor accepting the original type as its argument. [heading Header] #include #include [heading Synopsis] namespace traits { template struct deduce_sequence { typedef __unspecified__ type; }; } [heading Example] template struct holder { typename traits::deduce_sequence::type element; holder(Seq const & a) : element(a) { } }; template holder< __vector__ > make_holder(T0 const & a0, T1 const & a1) { typedef __vector__ arg_vec_t; return holder( arg_vec_t(a0,a1) ); } [heading See also] * __deduce__ [endsect] [section pair] [heading Description] Fusion `pair` type is a half runtime pair. A half runtime pair is similar to a __std_pair__, but, unlike __std_pair__, the first type does not have data. It is used as elements in __map__\ s, for example. [heading Synopsis] template struct pair; namespace result_of { template struct first; template struct second; template struct make_pair; } template typename result_of::make_pair::type make_pair(Second const &); [heading Template parameters] [table [[Parameter] [Description]] [[First] [The first type. This is purely a type. No data is held.]] [[Second] [The second type. This contains data.]] ] [variablelist Notation [[`P`] [Fusion pair type]] [[`p`, `p2`] [Fusion pairs]] [[`F`, `S`] [Arbitrary types]] [[`s`] [Value of type `S`]] [[`o`] [Output stream]] [[`i`] [Input stream]] ] [heading Expression Semantics] [table [[Expression] [Semantics]] [[`P::first_type`] [The type of the first template parameter, `F`, equivalent to `result_of::first

::type`. ]] [[`P::second_type`] [The type of the second template parameter, `S`, equivalent to `result_of::second

::type`. ]] [[`P()`] [Default construction.]] [[`P(s)`] [Construct a pair given value for the second type, `s`.]] [[`P(p2)`] [Copy constructs a pair from another pair, `p2`.]] [[`p.second`] [Get the data from `p1`.]] [[`p = p2`] [Assigns a pair, `p1`, from another pair, `p2`.]] [[make_pair(s)] [Make a pair given the first type, `F`, and a value for the second type, `s`. The second type assumes the type of `s`]] [[`o << p`] [Output `p` to output stream, `o`.]] [[`i >> p`] [Input `p` from input stream, `i`.]] [[`p == p2`] [Tests two pairs for equality.]] [[`p != p2`] [Tests two pairs for inequality.]] ] [heading Header] #include #include [heading Example] pair p('X'); std::cout << p << std::endl; std::cout << make_pair('X') << std::endl; assert((p == make_pair('X'))); [endsect] [endsect]