Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:42

0001 // (C) Copyright Jeremy Siek 2001.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 // Revision History:
0007 
0008 // 04 Oct 2001   David Abrahams
0009 //      Changed name of "bind" to "select" to avoid problems with MSVC.
0010 
0011 #ifndef BOOST_DETAIL_NAMED_TEMPLATE_PARAMS_HPP
0012 #define BOOST_DETAIL_NAMED_TEMPLATE_PARAMS_HPP
0013 
0014 #include <boost/config.hpp>
0015 #include <boost/type_traits/conversion_traits.hpp>
0016 #include <boost/type_traits/composite_traits.hpp> // for is_reference
0017 #if defined(BOOST_BORLANDC)
0018 #include <boost/type_traits/ice.hpp>
0019 #endif
0020 
0021 namespace boost {
0022   namespace detail {
0023     
0024     struct default_argument { };
0025 
0026     struct dummy_default_gen {
0027       template <class Base, class Traits>
0028       struct select {
0029         typedef default_argument type;
0030       };
0031     };
0032 
0033    // This class template is a workaround for MSVC.
0034    template <class Gen> struct default_generator {
0035      typedef detail::dummy_default_gen type;
0036    };
0037 
0038     template <class T> struct is_default { 
0039       enum { value = false };  
0040       typedef type_traits::no_type type;
0041     };
0042     template <> struct is_default<default_argument> { 
0043       enum { value = true }; 
0044       typedef type_traits::yes_type type;
0045     };
0046 
0047     struct choose_default {
0048       template <class Arg, class DefaultGen, class Base, class Traits>
0049       struct select {
0050         typedef typename default_generator<DefaultGen>::type Gen;
0051         typedef typename Gen::template select<Base,Traits>::type type;
0052       };
0053     };
0054     struct choose_arg {
0055       template <class Arg, class DefaultGen, class Base, class Traits>
0056       struct select {
0057         typedef Arg type;
0058       };
0059     };
0060 
0061 #if defined(BOOST_BORLANDC)
0062     template <class UseDefault>
0063     struct choose_arg_or_default { typedef choose_arg type; };
0064     template <>
0065     struct choose_arg_or_default<type_traits::yes_type> {
0066       typedef choose_default type;
0067     };
0068 #else
0069     template <bool UseDefault>
0070     struct choose_arg_or_default { typedef choose_arg type; };
0071     template <>
0072     struct choose_arg_or_default<true> {
0073       typedef choose_default type;
0074     };
0075 #endif
0076     
0077     template <class Arg, class DefaultGen, class Base, class Traits>
0078     class resolve_default {
0079 #if defined(BOOST_BORLANDC)
0080       typedef typename choose_arg_or_default<typename is_default<Arg>::type>::type Selector;
0081 #else
0082       // This usually works for Borland, but I'm seeing weird errors in
0083       // iterator_adaptor_test.cpp when using this method.
0084       enum { is_def = is_default<Arg>::value };
0085       typedef typename choose_arg_or_default<is_def>::type Selector;
0086 #endif
0087     public:
0088       typedef typename Selector
0089         ::template select<Arg, DefaultGen, Base, Traits>::type type;
0090     };
0091 
0092     // To differentiate an unnamed parameter from a traits generator
0093     // we use is_convertible<X, iter_traits_gen_base>.
0094     struct named_template_param_base { };
0095 
0096     template <class X>
0097     struct is_named_param_list {
0098       enum { value  = is_convertible<X, named_template_param_base>::value };
0099     };
0100     
0101     struct choose_named_params {
0102       template <class Prev> struct select { typedef Prev type; };
0103     };
0104     struct choose_default_arg {
0105       template <class Prev> struct select { 
0106         typedef detail::default_argument type;
0107       };
0108     };
0109 
0110     template <bool Named> struct choose_default_dispatch_;
0111     template <> struct choose_default_dispatch_<true> {
0112       typedef choose_named_params type;
0113     };
0114     template <> struct choose_default_dispatch_<false> {
0115       typedef choose_default_arg type;
0116     };
0117     // The use of inheritance here is a Solaris Forte 6 workaround.
0118     template <bool Named> struct choose_default_dispatch
0119       : public choose_default_dispatch_<Named> { };
0120 
0121     template <class PreviousArg>
0122     struct choose_default_argument {
0123       enum { is_named = is_named_param_list<PreviousArg>::value };
0124       typedef typename choose_default_dispatch<is_named>::type Selector;
0125       typedef typename Selector::template select<PreviousArg>::type type;
0126     };
0127 
0128     // This macro assumes that there is a class named default_##TYPE
0129     // defined before the application of the macro.  This class should
0130     // have a single member class template named "select" with two
0131     // template parameters: the type of the class being created (e.g.,
0132     // the iterator_adaptor type when creating iterator adaptors) and
0133     // a traits class. The select class should have a single typedef
0134     // named "type" that produces the default for TYPE.  See
0135     // boost/iterator_adaptors.hpp for an example usage.  Also,
0136     // applications of this macro must be placed in namespace
0137     // boost::detail.
0138 
0139 #define BOOST_NAMED_TEMPLATE_PARAM(TYPE) \
0140     struct get_##TYPE##_from_named { \
0141       template <class Base, class NamedParams, class Traits> \
0142       struct select { \
0143           typedef typename NamedParams::traits NamedTraits; \
0144           typedef typename NamedTraits::TYPE TYPE; \
0145           typedef typename resolve_default<TYPE, \
0146             default_##TYPE, Base, NamedTraits>::type type; \
0147       }; \
0148     }; \
0149     struct pass_thru_##TYPE { \
0150       template <class Base, class Arg, class Traits> struct select { \
0151           typedef typename resolve_default<Arg, \
0152             default_##TYPE, Base, Traits>::type type; \
0153       };\
0154     }; \
0155     template <int NamedParam> \
0156     struct get_##TYPE##_dispatch { }; \
0157     template <> struct get_##TYPE##_dispatch<1> { \
0158       typedef get_##TYPE##_from_named type; \
0159     }; \
0160     template <> struct get_##TYPE##_dispatch<0> { \
0161       typedef pass_thru_##TYPE type; \
0162     }; \
0163     template <class Base, class X, class Traits>  \
0164     class get_##TYPE { \
0165       enum { is_named = is_named_param_list<X>::value }; \
0166       typedef typename get_##TYPE##_dispatch<is_named>::type Selector; \
0167     public: \
0168       typedef typename Selector::template select<Base, X, Traits>::type type; \
0169     }; \
0170     template <> struct default_generator<default_##TYPE> { \
0171       typedef default_##TYPE type; \
0172     }
0173 
0174     
0175   } // namespace detail
0176 } // namespace boost
0177 
0178 #endif // BOOST_DETAIL_NAMED_TEMPLATE_PARAMS_HPP