From 957c79bbb4dd121a7de396483fb4651b57f53615 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Mon, 25 Nov 2002 07:07:03 +0000 Subject: [PATCH] is_sequence initial checkin [SVN r16398] --- include/boost/mpl/aux_/begin_end_impl.hpp | 48 ++++++++++------ include/boost/mpl/aux_/has_begin.hpp | 26 +++++++++ include/boost/mpl/aux_/has_rebind.hpp | 2 +- include/boost/mpl/aux_/has_tag.hpp | 26 +++++++++ include/boost/mpl/aux_/has_xxx.hpp | 18 +++--- include/boost/mpl/aux_/sequence_tag.hpp | 10 +++- include/boost/mpl/is_sequence.hpp | 51 +++++++++++++++++ include/boost/mpl/sequence_tag.hpp | 68 +++++++++++++++++++++-- include/boost/mpl/sequence_tag_fwd.hpp | 29 ++++++++++ 9 files changed, 242 insertions(+), 36 deletions(-) create mode 100644 include/boost/mpl/aux_/has_begin.hpp create mode 100644 include/boost/mpl/aux_/has_tag.hpp create mode 100644 include/boost/mpl/is_sequence.hpp create mode 100644 include/boost/mpl/sequence_tag_fwd.hpp diff --git a/include/boost/mpl/aux_/begin_end_impl.hpp b/include/boost/mpl/aux_/begin_end_impl.hpp index 76ada67..96bfc7a 100644 --- a/include/boost/mpl/aux_/begin_end_impl.hpp +++ b/include/boost/mpl/aux_/begin_end_impl.hpp @@ -18,6 +18,7 @@ #define BOOST_MPL_AUX_BEGIN_END_IMPL_HPP_INCLUDED #include "boost/mpl/begin_end_fwd.hpp" +#include "boost/mpl/sequence_tag_fwd.hpp" #include "boost/mpl/aux_/traits_lambda_spec.hpp" #include "boost/mpl/aux_/config/eti.hpp" @@ -25,8 +26,8 @@ namespace boost { namespace mpl { // default implementation; conrete sequences might override it by -// specializing either the |begin_traits/end_traits| or the primary -// |begin/end| templates +// specializing either the 'begin_traits/end_traits' or the primary +// 'begin/end' templates template< typename Tag > struct begin_traits @@ -46,24 +47,37 @@ struct end_traits }; }; -#if defined(BOOST_MPL_MSVC_ETI_BUG) -template<> struct begin_traits -{ - template< typename Sequence > struct algorithm - { - typedef int type; - }; -}; +// specialize 'begin_trait/end_trait' for two pre-defined tags -template<> struct end_traits -{ - template< typename Sequence > struct algorithm - { - typedef int type; - }; -}; +# define AUX_AGLORITM_TRAIT_SPEC(name, tag, result) \ +template<> \ +struct name##_traits \ +{ \ + template< typename Sequence > struct algorithm \ + { \ + typedef result type; \ + }; \ +}; \ +/**/ + +// a sequence with nested 'begin/end' typedefs; just query them +AUX_AGLORITM_TRAIT_SPEC(begin, nested_begin_end_tag, typename Sequence::begin) +AUX_AGLORITM_TRAIT_SPEC(end, nested_begin_end_tag, typename Sequence::end) + +// if a type 'T' does not contain 'begin/end' or 'tag' members +// and doesn't specialize either 'begin/end' or 'begin_traits/end_traits' +// templates, then we end up here +AUX_AGLORITM_TRAIT_SPEC(begin, non_sequence_tag, non_sequence_tag) +AUX_AGLORITM_TRAIT_SPEC(end, non_sequence_tag, non_sequence_tag) + +#if defined(BOOST_MPL_MSVC_ETI_BUG) +AUX_AGLORITM_TRAIT_SPEC(begin, int, non_sequence_tag) +AUX_AGLORITM_TRAIT_SPEC(end, int, non_sequence_tag) #endif +# undef AUX_AGLORITM_TRAIT_SPEC + + BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(1,begin_traits) BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(1,end_traits) diff --git a/include/boost/mpl/aux_/has_begin.hpp b/include/boost/mpl/aux_/has_begin.hpp new file mode 100644 index 0000000..b95eba8 --- /dev/null +++ b/include/boost/mpl/aux_/has_begin.hpp @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------------- +// boost mpl/aux_/has_begin.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2002 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#ifndef BOOST_MPL_AUX_HAS_BEGIN_HPP_INCLUDED +#define BOOST_MPL_AUX_HAS_BEGIN_HPP_INCLUDED + +#include "boost/mpl/aux_/has_xxx.hpp" + +namespace boost { namespace mpl { namespace aux { +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_begin, begin, true) +}}} + +#endif // BOOST_MPL_AUX_HAS_BEGIN_HPP_INCLUDED diff --git a/include/boost/mpl/aux_/has_rebind.hpp b/include/boost/mpl/aux_/has_rebind.hpp index 3916fbc..5dadb95 100644 --- a/include/boost/mpl/aux_/has_rebind.hpp +++ b/include/boost/mpl/aux_/has_rebind.hpp @@ -24,7 +24,7 @@ namespace boost { namespace mpl { namespace aux { -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_rebind_impl, rebind) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_rebind_impl, rebind, false) template< typename T > struct has_rebind diff --git a/include/boost/mpl/aux_/has_tag.hpp b/include/boost/mpl/aux_/has_tag.hpp new file mode 100644 index 0000000..6368b8a --- /dev/null +++ b/include/boost/mpl/aux_/has_tag.hpp @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------------- +// boost mpl/aux_/has_tag.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2002 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#ifndef BOOST_MPL_AUX_HAS_TAG_HPP_INCLUDED +#define BOOST_MPL_AUX_HAS_TAG_HPP_INCLUDED + +#include "boost/mpl/aux_/has_xxx.hpp" + +namespace boost { namespace mpl { namespace aux { +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_tag, tag, true) +}}} + +#endif // BOOST_MPL_AUX_HAS_TAG_HPP_INCLUDED diff --git a/include/boost/mpl/aux_/has_xxx.hpp b/include/boost/mpl/aux_/has_xxx.hpp index 02c951a..07b867d 100644 --- a/include/boost/mpl/aux_/has_xxx.hpp +++ b/include/boost/mpl/aux_/has_xxx.hpp @@ -32,7 +32,7 @@ // the implementation below is based on a USENET newsgroup's posting by // Rani Sharoni (comp.lang.c++.moderated, 2002-03-17 07:45:09 PST) -# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name) \ +# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \ template< typename T > \ boost::mpl::aux::yes_tag \ trait##_helper( \ @@ -66,7 +66,7 @@ namespace boost { namespace mpl { namespace aux { struct has_xxx_tag; }}} -# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name) \ +# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \ template< typename T, typename name = ::boost::mpl::aux::has_xxx_tag > \ struct trait : T \ { \ @@ -105,13 +105,13 @@ template<> struct trait \ /**/ #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) -# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name) \ - BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name) \ +# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \ + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \ BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, wchar_t) \ /**/ #else -# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name) \ - BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name) \ +# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \ + BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \ /**/ #endif @@ -119,18 +119,18 @@ template<> struct trait \ #else -# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name) \ +# define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_value) \ template< typename T > \ struct trait \ { \ - BOOST_STATIC_CONSTANT(bool, value = false); \ + BOOST_STATIC_CONSTANT(bool, value = default_value); \ }; \ /**/ #endif // BOOST_MPL_BROKEN_OVERLOAD_RESOLUTION #define BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \ -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_##name, name) \ +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_##name, name, false) \ /**/ #endif // BOOST_MPL_AUX_HAS_XXX_HPP_INCLUDED diff --git a/include/boost/mpl/aux_/sequence_tag.hpp b/include/boost/mpl/aux_/sequence_tag.hpp index a0a1fab..1f41ca3 100644 --- a/include/boost/mpl/aux_/sequence_tag.hpp +++ b/include/boost/mpl/aux_/sequence_tag.hpp @@ -20,10 +20,14 @@ //#include "boost/mpl/aux_/config/internal.hpp" #include "boost/config.hpp" -#if defined(BOOST_MPL_INTERNAL_USE_SEQUENCE_TAG) || \ - defined(BOOST_MSVC) && BOOST_MSVC < 1300 -# include "boost/mpl/sequence_tag.hpp" +#if !defined(BOOST_MPL_INTERNAL_USE_SEQUENCE_TAG) +# define BOOST_MPL_INTERNAL_USE_SEQUENCE_TAG +#endif +#if defined(BOOST_MPL_INTERNAL_USE_SEQUENCE_TAG) \ + || defined(BOOST_MSVC) && BOOST_MSVC < 1300 + +# include "boost/mpl/sequence_tag.hpp" # define BOOST_MPL_AUX_SEQUENCE_TAG(seq) sequence_tag::type #else diff --git a/include/boost/mpl/is_sequence.hpp b/include/boost/mpl/is_sequence.hpp new file mode 100644 index 0000000..032ffc1 --- /dev/null +++ b/include/boost/mpl/is_sequence.hpp @@ -0,0 +1,51 @@ +//----------------------------------------------------------------------------- +// boost mpl/is_sequence.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2002 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#ifndef BOOST_MPL_IS_SEQUENCE_HPP_INCLUDED +#define BOOST_MPL_IS_SEQUENCE_HPP_INCLUDED + +#include "boost/mpl/logical/not.hpp" +#include "boost/mpl/begin_end.hpp" +#include "boost/mpl/sequence_tag_fwd.hpp" +#include "boost/mpl/aux_/void_spec.hpp" +#include "boost/mpl/aux_/lambda_support.hpp" +#include "boost/mpl/aux_/config/eti.hpp" + +#include "boost/type_traits/is_same.hpp" + +namespace boost { namespace mpl { + +template< + typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) + > +struct is_sequence + : logical_not< is_same< typename begin::type, non_sequence_tag > > +{ + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_sequence,(T)) +}; + +#if defined(BOOST_MPL_MSVC_ETI_BUG) +template<> struct is_sequence + : bool_c +{ +}; +#endif + +BOOST_MPL_AUX_VOID_SPEC(1, is_sequence) + +}} // namespace boost::mpl + +#endif // BOOST_MPL_IS_SEQUENCE_HPP_INCLUDED diff --git a/include/boost/mpl/sequence_tag.hpp b/include/boost/mpl/sequence_tag.hpp index 35cf8e5..40fd291 100644 --- a/include/boost/mpl/sequence_tag.hpp +++ b/include/boost/mpl/sequence_tag.hpp @@ -17,30 +17,86 @@ #ifndef BOOST_MPL_SEQUENCE_TAG_HPP_INCLUDED #define BOOST_MPL_SEQUENCE_TAG_HPP_INCLUDED +#include "boost/mpl/sequence_tag_fwd.hpp" +#include "boost/mpl/aux_/has_tag.hpp" +#include "boost/mpl/aux_/has_begin.hpp" #include "boost/mpl/aux_/void_spec.hpp" #include "boost/mpl/aux_/config/eti.hpp" -namespace boost { -namespace mpl { +#include "boost/type_traits/is_class.hpp" + +namespace boost { namespace mpl { + +namespace aux { + +template< bool has_tag_, bool has_begin_ > +struct class_sequence_tag_impl +{ + // agurt 24/nov/02: MSVC 6.5 gets confused in 'sequence_tag_impl' + // specialization below, if we name it 'result_' here + template< typename Sequence > struct result2_; +}; + +# define AUX_CLASS_SEQUENCE_TAG_SPEC(has_tag, has_begin, result_type) \ +template<> struct class_sequence_tag_impl \ +{ \ + template< typename Sequence > struct result2_ \ + { \ + typedef result_type type; \ + }; \ +}; \ +/**/ + +AUX_CLASS_SEQUENCE_TAG_SPEC(true, true, typename Sequence::tag) +AUX_CLASS_SEQUENCE_TAG_SPEC(true, false, typename Sequence::tag) +AUX_CLASS_SEQUENCE_TAG_SPEC(false, true, nested_begin_end_tag) +AUX_CLASS_SEQUENCE_TAG_SPEC(false, false, non_sequence_tag) + +# undef AUX_CLASS_SEQUENCE_TAG_SPEC + + +template< bool is_class_ > +struct sequence_tag_impl +{ + template< typename Sequence > struct result_ + { + typedef non_sequence_tag type; + }; +}; + +template<> +struct sequence_tag_impl +{ + template< typename Sequence > struct result_ + : class_sequence_tag_impl< + ::boost::mpl::aux::has_tag::value + , ::boost::mpl::aux::has_begin::value + >::template result2_ + { + }; +}; + +} // namespace aux template< typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) > struct sequence_tag + : aux::sequence_tag_impl< + ::boost::is_class::value + >::template result_ { - typedef typename Sequence::tag type; }; #if defined(BOOST_MPL_MSVC_ETI_BUG) template<> struct sequence_tag { - typedef int type; + typedef non_sequence_tag type; }; #endif BOOST_MPL_AUX_VOID_SPEC(1, sequence_tag) -} // namespace mpl -} // namespace boost +}} // namespace boost::mpl #endif // BOOST_MPL_SEQUENCE_TAG_HPP_INCLUDED diff --git a/include/boost/mpl/sequence_tag_fwd.hpp b/include/boost/mpl/sequence_tag_fwd.hpp new file mode 100644 index 0000000..704dc46 --- /dev/null +++ b/include/boost/mpl/sequence_tag_fwd.hpp @@ -0,0 +1,29 @@ +//----------------------------------------------------------------------------- +// boost mpl/sequence_tag_fwd.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2000-02 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#ifndef BOOST_MPL_SEQUENCE_TAG_FWD_HPP_INCLUDED +#define BOOST_MPL_SEQUENCE_TAG_FWD_HPP_INCLUDED + +namespace boost { namespace mpl { + +struct nested_begin_end_tag; +struct non_sequence_tag; + +template< typename Sequence > struct sequence_tag; + +}} // namespace boost::mpl + +#endif // BOOST_MPL_SEQUENCE_TAG_FWD_HPP_INCLUDED