Ticket #2793: arg_list.diff

File arg_list.diff, 4.4 KB (added by Louis Dionne <louis.dionne92@…>, 10 years ago)

temporary workaround

  • boost/parameter/aux_/arg_list.hpp

     
    2525#include <boost/preprocessor/repetition/enum_params.hpp>
    2626#include <boost/preprocessor/repetition/enum_binary_params.hpp>
    2727#include <boost/preprocessor/facilities/intercept.hpp>
     28#include <boost/utility/enable_if.hpp>
    2829
    2930namespace boost { namespace parameter {
    3031
     
    187188      , typename TaggedArg::value_type
    188189    >::type value_type;
    189190
     191private:
     192    // This metafunction is used to make a type dependent on a template
     193    // parameter. This is required below to delay the instantiation of the
     194    // return type of functions.
     195    // Since `arg_list` is used for named template parameters, the `reference`
     196    // type can't always be expected to be a type valid as a return type
     197    // (it could legitimately be a function type or an array type). Unless
     198    // delayed, the function signatures are instantiated even when the
     199    // functions are not actually used (in the case of named template
     200    // parameters) because of how the `arg_list` is implemented; by means
     201    // of inheritance from `Next`.
     202    //
     203    // Note: In the code below, we sometimes use enable_if with is_same
     204    //       when the signature is not really dependent on anything but
     205    //       we still need to introduce a template parameter to have a
     206    //       dependent return type.
     207    template <class Dummy, class Type>
     208    struct make_dependent_on {
     209        typedef Type type;
     210    };
     211
     212public:
     213
    190214    TaggedArg arg;      // Stores the argument
    191215
    192216    // Store the arguments in successive nodes of this list
     
    255279    // Helpers that handle the case when TaggedArg is
    256280    // empty<T>.
    257281    template <class D>
    258     reference get_default(D const&, mpl::false_) const
     282    typename make_dependent_on<D, reference>::type
     283    get_default(D const&, mpl::false_) const
    259284    {
    260285        return arg.value;
    261286    }
    262287
    263288    template <class D>
    264     reference get_default(D const& d, mpl::true_) const
     289    typename make_dependent_on<D, reference>::type
     290    get_default(D const& d, mpl::true_) const
    265291    {
    266292        return arg.value ? arg.value.get() : arg.value.construct(d.value);
    267293    }
     
    323349    // reached, indicating no matching argument was passed, the
    324350    // default is returned, or if no default_ or lazy_default was
    325351    // passed, compilation fails.
    326     reference get(keyword<key_type> const&) const
     352
     353    // Note: See the comment @make_dependent_on to know the rationale behind
     354    //       the use of enable_if with is_same instead of a straight overload.
     355    template <class KeyType>
     356    typename enable_if<is_same<KeyType, key_type>,
     357    reference>::type get(keyword<KeyType> const&) const
    327358    {
    328359        BOOST_MPL_ASSERT_NOT((holds_maybe));
    329360        return arg.value;
    330361    }
    331362
    332363    template <class Default>
    333     reference get(default_<key_type,Default> const& d) const
     364    typename make_dependent_on<Default, reference>::type
     365    get(default_<key_type,Default> const& d) const
    334366    {
    335367        return get_default(d, holds_maybe());
    336368    }
    337369
    338370    template <class Default>
    339     reference get(lazy_default<key_type, Default>) const
     371    typename make_dependent_on<Default, reference>::type
     372    get(lazy_default<key_type, Default>) const
    340373    {
    341374        return arg.value;
    342375    }
    343376
    344377#else
    345378
    346     reference operator[](keyword<key_type> const&) const
     379    // Note: See the comment @make_dependent_on to know the rationale behind
     380    //       the use of enable_if with is_same instead of a straight overload.
     381    template <class KeyType>
     382    typename enable_if<is_same<KeyType, key_type>,
     383    reference>::type operator[](keyword<KeyType> const&) const
    347384    {
    348385        BOOST_MPL_ASSERT_NOT((holds_maybe));
    349386        return arg.value;
    350387    }
    351388
    352389    template <class Default>
    353     reference operator[](default_<key_type, Default> const& d) const
     390    typename make_dependent_on<Default, reference>::type
     391    operator[](default_<key_type, Default> const& d) const
    354392    {
    355393        return get_default(d, holds_maybe());
    356394    }
    357395
    358396    template <class Default>
    359     reference operator[](lazy_default<key_type, Default>) const
     397    typename make_dependent_on<Default, reference>::type
     398    operator[](lazy_default<key_type, Default>) const
    360399    {
    361400        return arg.value;
    362401    }