From 95d2a111aba04bae9be3460ee08c13760d4fcea9 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sun, 9 Nov 2014 02:55:59 +0900 Subject: [PATCH 1/5] Add tests for #3225 --- test/sequence/map_misc.cpp | 12 ++++++++++++ test/sequence/misc.hpp | 12 ++++++++++++ test/sequence/set.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/test/sequence/map_misc.cpp b/test/sequence/map_misc.cpp index 256a16f4..81da9753 100644 --- a/test/sequence/map_misc.cpp +++ b/test/sequence/map_misc.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -148,6 +149,17 @@ test() BOOST_STATIC_ASSERT(!traits::is_sequence::value); } + { // testing mpl::is_sequence + + typedef map, pair, pair > t1; + typedef map<> t2; + typedef map > t3; + + BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); + BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); + BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); + } + { // testing mpl compatibility // test an algorithm diff --git a/test/sequence/misc.hpp b/test/sequence/misc.hpp index ecbe1549..c426bba8 100644 --- a/test/sequence/misc.hpp +++ b/test/sequence/misc.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -175,6 +176,17 @@ test() BOOST_STATIC_ASSERT(!traits::is_sequence::value); } + { // testing mpl::is_sequence + + typedef FUSION_SEQUENCE t1; + typedef FUSION_SEQUENCE<> t2; + typedef FUSION_SEQUENCE t3; + + BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); + BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); + BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); + } + { // testing mpl compatibility // test begin, end, next, prior, advance, size, deref, etc. diff --git a/test/sequence/set.cpp b/test/sequence/set.cpp index 1ea6ba24..cf97c100 100644 --- a/test/sequence/set.cpp +++ b/test/sequence/set.cpp @@ -18,8 +18,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -78,6 +80,28 @@ main() BOOST_TEST(at_key(make_set('X', 123)) == 123); } + { // testing is_sequence + + typedef set t1; + typedef set<> t2; + typedef set t3; + + BOOST_MPL_ASSERT((traits::is_sequence)); + BOOST_MPL_ASSERT((traits::is_sequence)); + BOOST_MPL_ASSERT((traits::is_sequence)); + } + + { // testing mpl::is_sequence + + typedef set t1; + typedef set<> t2; + typedef set t3; + + BOOST_MPL_ASSERT((boost::mpl::is_sequence)); + BOOST_MPL_ASSERT((boost::mpl::is_sequence)); + BOOST_MPL_ASSERT((boost::mpl::is_sequence)); + } + return boost::report_errors(); } From 916df63a14200072cad10d7b376c5b99f638c0b9 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 10 Nov 2014 14:32:23 +0900 Subject: [PATCH 2/5] Add result_of::{copy,move}, close #5886 Thanks to: Jamboree --- doc/algorithm.qbk | 115 +++++++++++++++++- doc/fusion.qbk | 3 + doc/html/index.html | 5 +- .../boost/fusion/algorithm/auxiliary/copy.hpp | 9 ++ .../boost/fusion/algorithm/auxiliary/move.hpp | 9 ++ 5 files changed, 139 insertions(+), 2 deletions(-) diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index 9ad943ee..dcb911fd 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -69,7 +69,7 @@ It is also used to convert sequence into other. [heading Synopsis] template - void copy(Seq1 const& src, Seq2& dest); + typename __result_of_copy__::type copy(Seq1 const& src, Seq2& dest); [table Parameters [[Parameter][Requirement][Description]] @@ -100,6 +100,119 @@ Linear, exactly `__result_of_size__::value`. [endsect] +[section move] + +[heading Description] +move a sequence `src` to a sequence `dest`. +It is also used to convert sequence into other. + +[heading Synopsis] + template + typename __result_of_move__::type move(Seq1&& src, Seq2& dest); + +[table Parameters + [[Parameter][Requirement][Description]] + [[`src`][A model of __forward_sequence__, all elements contained in the `src` sequence should be convertible into the element contained in the `dest` sequence.][Operation's argument]] + [[`dest`][A model of __forward_sequence__, `e2 = std::move(e1)` is valid expression for each pair of elements `e1` of `src` and `e2` of `dest`.][Operation's argument]] +] + +[heading Expression Semantics] + __move__(src, dest); + +[*Return type]: `void` + +[*Semantics]: `e2 = std::move(e1)` for each element `e1` in `src` and `e2` in `dest`. + +[heading Complexity] +Linear, exactly `__result_of_size__::value`. + +[heading Header] + + #include + #include + +[heading Example] + __vector__ vec(1,2); + __list__ ls; + __move__(std::move(vec), ls); + assert(ls == __make_list__(1,2)); + +[endsect] + +[endsect] + +[section Metafunctions] + +[section copy] + +[heading Description] +A metafunction returning the result type of applying __copy__, which is always `void`. + +[heading Synopsis] + template + struct copy + { + typedef void type; + }; + +[table Parameters + [[Parameter] [Requirement] [Description]] + [[`Seq1`] [A model of __forward_sequence__] [Operation's argument]] + [[`Seq2`] [A model of __forward_sequence__] [Operation's argument]] +] + +[heading Expression Semantics] + result_of::copy::type + +[*Return type]: `void` + +[*Semantics]: Returns the return type of __copy__ for 2 sequences of types `Seq1` and `Seq2`. + +[heading Complexity] +Constant. + +[heading Header] + + #include + #include + +[endsect] + +[section move] + +[heading Description] +A metafunction returning the result type of applying __move__, which is always `void`. + +[heading Synopsis] + template + struct move + { + typedef void type; + }; + +[table Parameters + [[Parameter] [Requirement] [Description]] + [[`Seq1`] [A model of __forward_sequence__] [Operation's argument]] + [[`Seq2`] [A model of __forward_sequence__] [Operation's argument]] +] + +[heading Expression Semantics] + result_of::move::type + +[*Return type]: `void` + +[*Semantics]: Returns the return type of __move__ for 2 sequences of types `Seq1` and `Seq2`. + +[heading Complexity] +Constant. + +[heading Header] + + #include + #include + +[endsect] + [endsect] [endsect] diff --git a/doc/fusion.qbk b/doc/fusion.qbk index f5d921de..7a943c14 100644 --- a/doc/fusion.qbk +++ b/doc/fusion.qbk @@ -226,6 +226,9 @@ [def __algorithm__ [link fusion.algorithm Algorithm]] [def __algorithms__ [link fusion.algorithm Algorithms]] [def __copy__ [link fusion.algorithm.auxiliary.functions.copy `copy`]] +[def __result_of_copy__ [link fusion.algorithm.auxiliary.metafunctions.copy `result_of::copy`]] +[def __move__ [link fusion.algorithm.auxiliary.functions.move `move`]] +[def __result_of_move__ [link fusion.algorithm.auxiliary.metafunctions.move `result_of::move`]] [def __fold__ [link fusion.algorithm.iteration.functions.fold `fold`]] [def __result_of_fold__ [link fusion.algorithm.iteration.metafunctions.fold `result_of::fold`]] [def __reverse_fold__ [link fusion.algorithm.iteration.functions.reverse_fold `reverse_fold`]] diff --git a/doc/html/index.html b/doc/html/index.html index 2279bd54..03b417ee 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -190,7 +190,10 @@
Algorithm
Auxiliary
-
Functions
+
+
Functions
+
Metafunctions
+
Iteration
Functions
diff --git a/include/boost/fusion/algorithm/auxiliary/copy.hpp b/include/boost/fusion/algorithm/auxiliary/copy.hpp index f8e16e92..dab1a410 100644 --- a/include/boost/fusion/algorithm/auxiliary/copy.hpp +++ b/include/boost/fusion/algorithm/auxiliary/copy.hpp @@ -60,6 +60,15 @@ namespace boost { namespace fusion }; } + namespace result_of + { + template + struct copy + { + typedef void type; + }; + } + template BOOST_FUSION_GPU_ENABLED inline typename enable_if + struct move + { + typedef void type; + }; + } + template BOOST_FUSION_GPU_ENABLED inline typename enable_if Date: Mon, 10 Nov 2014 14:34:02 +0900 Subject: [PATCH 3/5] fusion::swap should be inline --- include/boost/fusion/sequence/intrinsic/swap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/fusion/sequence/intrinsic/swap.hpp b/include/boost/fusion/sequence/intrinsic/swap.hpp index 6eca3146..5b00caac 100644 --- a/include/boost/fusion/sequence/intrinsic/swap.hpp +++ b/include/boost/fusion/sequence/intrinsic/swap.hpp @@ -51,7 +51,7 @@ namespace boost { namespace fusion { template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED - typename enable_if, traits::is_sequence >, void>::type + inline typename enable_if, traits::is_sequence >, void>::type swap(Seq1& lhs, Seq2& rhs) { typedef vector references; From 465c3f273b59e4341a249d05bb9fc856f50722fe Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 10 Nov 2014 14:38:42 +0900 Subject: [PATCH 4/5] result_of::{copy,move,swap} are now SFINAE-friendly --- doc/algorithm.qbk | 6 ++++-- doc/fusion.qbk | 2 ++ doc/sequence.qbk | 13 +++++++++---- include/boost/fusion/algorithm/auxiliary/copy.hpp | 12 +++++------- include/boost/fusion/algorithm/auxiliary/move.hpp | 12 +++++------- include/boost/fusion/sequence/intrinsic/swap.hpp | 12 +++++++----- 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index dcb911fd..d902ebe4 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -164,7 +164,8 @@ A metafunction returning the result type of applying __copy__, which is always ` [heading Expression Semantics] result_of::copy::type -[*Return type]: `void` +[*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence. +Otherwise, none. [*Semantics]: Returns the return type of __copy__ for 2 sequences of types `Seq1` and `Seq2`. @@ -199,7 +200,8 @@ A metafunction returning the result type of applying __move__, which is always ` [heading Expression Semantics] result_of::move::type -[*Return type]: `void` +[*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence. +Otherwise, none. [*Semantics]: Returns the return type of __move__ for 2 sequences of types `Seq1` and `Seq2`. diff --git a/doc/fusion.qbk b/doc/fusion.qbk index 7a943c14..f6c5f654 100644 --- a/doc/fusion.qbk +++ b/doc/fusion.qbk @@ -178,6 +178,8 @@ [def __result_of_value_at__ [link fusion.sequence.intrinsic.metafunctions.value_at `result_of::value_at`]] [def __result_of_value_at_c__ [link fusion.sequence.intrinsic.metafunctions.value_at_c `result_of::value_at_c`]] [def __result_of_value_at_key__ [link fusion.sequence.intrinsic.metafunctions.value_at_key `result_of::value_at_key`]] +[def __swap__ [link fusion.sequence.intrinsic.functions.swap `swap`]] +[def __result_of_swap__ [link fusion.sequence.intrinsic.metafunctions.swap `result_of::swap`]] [def __conversion__ [link fusion.container.conversion.functions Conversion]] [def __result_of_conversion__ [link fusion.container.conversion.metafunctions Conversion Metafunctions]] diff --git a/doc/sequence.qbk b/doc/sequence.qbk index 40558cb7..3948a2ce 100644 --- a/doc/sequence.qbk +++ b/doc/sequence.qbk @@ -854,7 +854,8 @@ Performs an element by element swap of the elements in 2 sequences. [heading Synopsis] template - void swap(Seq1& seq1, Seq2& seq2); + typename __result_of_swap__::type + swap(Seq1& seq1, Seq2& seq2); [heading Parameters] @@ -873,7 +874,10 @@ Performs an element by element swap of the elements in 2 sequences. [*Semantics]: Calls `swap(a1, b1)` for corresponding elements in `seq1` and `seq2`. -/sequence/intrinsic/swap.hpp> +[heading Header] + + #include + #include [heading Example] __vector__ v1(1, "hello"), v2(2, "world"); @@ -1415,9 +1419,10 @@ Returns the return type of swap. [heading Expression Semantics] result_of::swap::type -[*Return type]: `void`. +[*Return type]: `void` iff both of `Seq1` and `Seq2` are sequence. +Otherwise, none. -[*Semantics]: Always returns `void`. +[*Semantics]: Returns the return type of __swap__ for 2 sequences of types `Seq1` and `Seq2`. [heading Header] diff --git a/include/boost/fusion/algorithm/auxiliary/copy.hpp b/include/boost/fusion/algorithm/auxiliary/copy.hpp index dab1a410..683a5c87 100644 --- a/include/boost/fusion/algorithm/auxiliary/copy.hpp +++ b/include/boost/fusion/algorithm/auxiliary/copy.hpp @@ -64,17 +64,15 @@ namespace boost { namespace fusion { template struct copy - { - typedef void type; - }; + : enable_if, + traits::is_sequence + > > {}; } template BOOST_FUSION_GPU_ENABLED - inline typename enable_if, - traits::is_sequence - > >::type + inline typename result_of::copy::type copy(Seq1 const& src, Seq2& dest) { BOOST_STATIC_ASSERT( diff --git a/include/boost/fusion/algorithm/auxiliary/move.hpp b/include/boost/fusion/algorithm/auxiliary/move.hpp index ea938111..76ff4692 100644 --- a/include/boost/fusion/algorithm/auxiliary/move.hpp +++ b/include/boost/fusion/algorithm/auxiliary/move.hpp @@ -64,17 +64,15 @@ namespace boost { namespace fusion { template struct move - { - typedef void type; - }; + : enable_if, + traits::is_sequence + > > {}; } template BOOST_FUSION_GPU_ENABLED - inline typename enable_if, - traits::is_sequence - > >::type + inline typename result_of::move::type move(Seq1&& src, Seq2& dest) { BOOST_STATIC_ASSERT( diff --git a/include/boost/fusion/sequence/intrinsic/swap.hpp b/include/boost/fusion/sequence/intrinsic/swap.hpp index 5b00caac..8c49dc48 100644 --- a/include/boost/fusion/sequence/intrinsic/swap.hpp +++ b/include/boost/fusion/sequence/intrinsic/swap.hpp @@ -14,19 +14,21 @@ #include #include #include -#include #include #include +#include #include namespace boost { namespace fusion { + namespace result_of { template struct swap - { - typedef void type; - }; + : enable_if, + traits::is_sequence + > > {}; } namespace detail @@ -51,7 +53,7 @@ namespace boost { namespace fusion { template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED - inline typename enable_if, traits::is_sequence >, void>::type + inline typename result_of::swap::type swap(Seq1& lhs, Seq2& rhs) { typedef vector references; From 06cac9da1a6a270f0d5d092c1871cc20baa629b4 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 10 Nov 2014 16:03:36 +0900 Subject: [PATCH 5/5] Fix document typo --- doc/sequence.qbk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sequence.qbk b/doc/sequence.qbk index 3948a2ce..2d323e37 100644 --- a/doc/sequence.qbk +++ b/doc/sequence.qbk @@ -1395,7 +1395,7 @@ Returns the actual element type associated with a Key from the __sequence__. [heading Example] typedef __map__<__pair__, __pair__, __pair__ > mymap; - BOOST_MPL_ASSERT((boost::is_same<__result_of_at_key__::type, char>)); + BOOST_MPL_ASSERT((boost::is_same<__result_of_value_at_key__::type, char>)); [endsect]