Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-08-18 10:25:57


David Abrahams wrote:
>
> FWIW, Boost.Function is overkill for many simple cases. This might
> be a case where the FS library should just provide a class with a
> virtual function:
>
> struct checker
> {
> virtual ~checker() {}
> virtual bool operator()( std string const& ) = 0;
>
> shared_ptr<checker> next; // suggested.
> };

Boost.Function makes things simpler for the user.

enum check_type { check_posix, check_windows, ... };
bool my_name_checker(std::string const & s, check_type t);

Compare

bind(my_name_checker, _1, check_posix)

against

struct my_name_checker_: public checker
{
    check_type t_;

    my_name_checker_(check_type t): t_(t) {}

    bool operator()( std::string const & s)
    {
        return my_name_checker(s, t_);
    }
};

It is still possible to substitute a homegrown function<bool(string)> (or
function<bool(char const *)>) equivalent for portability reasons, of course.


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