Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-11-18 09:49:12


On Thu, Nov 18, 2004 at 02:00:40PM +0000, Daniel James wrote:

> I've written a macro (the implementation is attached) for generating a
> function object for using overloaded functions with generic code such as
> the STL algorithms and boost::bind. A simple example of it's use:
[snip]
> Any comments on this? Would anyone else find this useful? Also, has
> anyone done something similar? I'd be surprised if no one has, I always
> feel like I'm missing something when I'm doing this kind of thing.

Out of curiosity my first thought was to see if I could use std::tolower
in std::transform, like so:

    #include "overloaded.hpp"
    #include <string>
    #include <algorithm>
    #include <cctype>

    using std::tolower;

    GENERATE_OVERLOADED(int, tolower);

    int main()
    {
        std::string s("FNORD");
        std::transform(s.begin(), s.end(), s.begin(), tolower_overloaded);
    }

(The using declaration is needed to prevent the instance of the generated
type being named "std::tolower_overloaded")

Unfortunately this fails to compile because there is no nullary form of
std::tolower so the nullary overload gives this error:

/usr/include/ctype.h: In member function `ResultType GENERATE_DETAIL::tolower_overloaded_t<ResultType>::operator()() const':
/usr/include/ctype.h:81: error: too few arguments to function `int tolower(int)'
tolower.cc:8: error: at this point in file

In fact, I get a similar error for the example code in your mail:

overloaded.cc: In member function `ResultType GENERATE_DETAIL::foo_overloaded_t<ResultType>::operator()() const':
overloaded.cc:7: error: no matching function for call to `foo()'
overloaded.cc:4: note: candidates are: void foo(int)
overloaded.cc:5: note: void foo(char*)

So although I can see uses for this, I can't use it :-)

jon

-- 
"The easy confidence with which I know another man's religion is Folly
 leads me to suspect that my own is also."
	- Mark Twain

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