Boost logo

Boost :

From: Rene Rivera (grafik.list_at_[hidden])
Date: 2004-11-14 15:45:25


I tried to follow along with the docs... But I can't get very far. With
CW8.3 I get:

### mwcc Compiler:
# File: named_params_ex1.cpp
# -----------------------------
# 42: std::cout << params[name] << " = " << params[value] << "\n";
# Error: ^
# pointer/array required
# (point of instantiation: 'foo()')
# (instantiating: 'foo_impl<boost::detail::nil>(const
boost::detail::nil &)')

And to see if it was just a CW problem, I also tried VC71:

..\..\temp\named_params\named_params_ex1.cpp(42) : error C2784:
'Default::result_type boost::detail::nil::operator [](const
boost::detail::lazy_named_default<K,Default> &) const' : could not
deduce template argument for 'const
boost::detail::lazy_named_default<KW,DefaultFn> &' from
'boost::keyword<Tag>'
         with
         [
             Tag=name_t
         ]
 
C:\CVSROOTs\Boost-Sandbox\boost-sandbox\boost\named_params.hpp(186) :
see declaration of 'boost::detail::nil::operator`[]''
         ..\..\temp\named_params\named_params_ex1.cpp(24) : see
reference to function template instantiation 'void
foo_impl<boost::detail::nil>(const Params &)' being compiled
         with
         [
             Params=boost::detail::nil
         ]
..\..\temp\named_params\named_params_ex1.cpp(42) : error C2784: 'Default
&boost::detail::nil::operator [](const
boost::detail::named_default<K,Default> &) const' : could not deduce
template argument for 'const boost::detail::named_default<KW,Default> &'
from 'boost::keyword<Tag>'
         with
         [
             Tag=name_t
         ]
 
C:\CVSROOTs\Boost-Sandbox\boost-sandbox\boost\named_params.hpp(172) :
see declaration of 'boost::detail::nil::operator`[]''
..\..\temp\named_params\named_params_ex1.cpp(42) : error C2676: binary
'[' : 'const boost::detail::nil' does not define this operator or a
conversion to a type acceptable to the predefined operator
..\..\temp\named_params\named_params_ex1.cpp(42) : error C2784:
'Default::result_type boost::detail::nil::operator [](const
boost::detail::lazy_named_default<K,Default> &) const' : could not
deduce template argument for 'const
boost::detail::lazy_named_default<KW,DefaultFn> &' from
'boost::keyword<Tag>'
         with
         [
             Tag=value_t
         ]
 
C:\CVSROOTs\Boost-Sandbox\boost-sandbox\boost\named_params.hpp(186) :
see declaration of 'boost::detail::nil::operator`[]''
..\..\temp\named_params\named_params_ex1.cpp(42) : error C2784: 'Default
&boost::detail::nil::operator [](const
boost::detail::named_default<K,Default> &) const' : could not deduce
template argument for 'const boost::detail::named_default<KW,Default> &'
from 'boost::keyword<Tag>'
         with
         [
             Tag=value_t
         ]
 
C:\CVSROOTs\Boost-Sandbox\boost-sandbox\boost\named_params.hpp(172) :
see declaration of 'boost::detail::nil::operator`[]''
..\..\temp\named_params\named_params_ex1.cpp(42) : error C2676: binary
'[' : 'const boost::detail::nil' does not define this operator or a
conversion to a type acceptable to the predefined operator

Makes it's kinda hard to understand when it fails like this :-(


#include <boost/named_params.hpp>
#include <iostream>

struct name_t; // tag types
struct value_t;

namespace {
  boost::keyword<name_t> name; // keyword objects
  boost::keyword<value_t> value;
}

struct foo_keywords
  : boost::keywords<
        name_t
      , value_t
>
{};

template<class Params>
void foo_impl(const Params&);

void foo()
{
    foo_impl(foo_keywords()());
}

template<class A0>
void foo(const A0& a0)
{
    foo_impl(foo_keywords()(a0));
}

template<class A0, class A1>
void foo(const A0& a0, const A1& a1)
{
    foo_impl(foo_keywords()(a0, a1));
}

template<class Params>
void foo_impl(const Params& params)
{
    std::cout << params[name] << " = " << params[value] << "\n";
}

int main()
{
    foo("bar", 3.14f);
    foo(value = 6.28f, "baz");
    
    return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk