Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-02-22 07:57:05


"Gennadiy Rozental" <gennadiy.rozental_at_[hidden]> writes:

> Hi,
>
> I found following issue: if I have const type in a list of types test case
> template facility initialized with, it really gets instantiated with non
> const type. After some investigation I found the reason. The reason is the
> mpl::for_each, used in the facility implementation, rely on type deduction
> based on type of single argument it passes. It works for simple function and
> function object. But it does not for function object with template
> operator(). It's all originated from the fact that following code compiles:
>
> struct {
> template<typename T>
> void operator()( T )
> {
> T t = 0;
> ++t;
> }
> } foo;
>
> int main()
> {
> char const x = 0;
>
> foo( x );
>
> return 0;
> }
>
> because foo.operator() is instantiated with type char - not char const.
>
> Is the any workarounds? Could we fix that?

template <class T>
struct wrap {};

typedef mpl::vector<int const, long&, char*&> s;

struct foo {
    template<typename T>
    void operator()( wrap<T> )
    {
        T t = 0;
        ++t;
    }
};

mpl::for_each<mpl::transform<s, wrap<_1> >::type>(foo());

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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