|
Boost : |
From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-11-14 16:45:35
Oops.. The example in the docs seems to be wrong. It's suppose to be:
int main()
{
foo("bar", 3.14f);
foo("baz", value = 6.28f);
return 0;
}
As written in the docs the "name" parameter doesn't get a value, thus
the compilation error. To get it to compile, the nullary foo_impl()
overload needs to be removed as well. It can never be valid since
neither of the arguments have default values.
Sorry about that.
Rene Rivera wrote:
> 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;
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Daniel Wallin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk