From 465c3f273b59e4341a249d05bb9fc856f50722fe Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 10 Nov 2014 14:38:42 +0900 Subject: [PATCH] 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;