Prev: WAVEHDR allocationg several buffers
Next: "PORTING" C > weird char array values displayed in watch window?
From: Stephen Howe on 15 Jan 2010 11:27 Hi Just reading "C++ Common Knowledge" - Stephen Dewhurst. According to this, deriving your functor from binary_function allows "other parts of the STL implementation to ask compile-time questions of the function object". Now does this occur for Visual Studio 8.0 ? Visual Studio 9.0 ? Visual Studio 10.0 ? Thanks Stephen Howe
From: Igor Tandetnik on 15 Jan 2010 13:32 Stephen Howe <sjhoweATdialDOTpipexDOTcom> wrote: > Just reading "C++ Common Knowledge" - Stephen Dewhurst. > > According to this, deriving your functor from binary_function allows > "other parts of the STL implementation to ask compile-time questions > of the function object". > > Now does this occur for > Visual Studio 8.0 ? > Visual Studio 9.0 ? > Visual Studio 10.0 ? Yes, STL implementation included with all these VS versions provides std::binary_function class that you can derive from, as well as certain wrappers and adapters that benefit from typedefs std::binary_function introduces. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Stephen Howe on 16 Jan 2010 16:21 >> Now does this occur for >> Visual Studio 8.0 ? >> Visual Studio 9.0 ? >> Visual Studio 10.0 ? > >Yes, STL implementation included with all these VS versions provides std::binary_function class that you can derive from... I was certain of that Igor >... as well as certain wrappers and adapters that benefit from typedefs std::binary_function introduces. What wrappers, adapters and benefits are those? Thanks Stephen Howe
From: Igor Tandetnik on 16 Jan 2010 17:08 Stephen Howe wrote: >>> Now does this occur for >>> Visual Studio 8.0 ? >>> Visual Studio 9.0 ? >>> Visual Studio 10.0 ? >> >> Yes, STL implementation included with all these VS versions provides std::binary_function class that you can derive from... > > I was certain of that Igor > >> ... as well as certain wrappers and adapters that benefit from typedefs std::binary_function introduces. > > What wrappers, adapters and benefits are those? E.g. binary_negate, which is defined something like this: template <class Predicate> class binary_negate : public binary_function< typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool> { bool operator() ( const first_argument_type& arg1, const second_argument_type& arg2) const { return !Predicate()(arg1, arg2); } }; Note how the template parameter (a user-defined predicate) is expected to provide typedefs named first_argument_type and second_argument_type. You can define them manually, or you can save some typing by deriving from binary_function. There are a few other adapters in the similar vein. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Tamas Demjen on 18 Jan 2010 16:32
Stephen Howe wrote: >> ... as well as certain wrappers and adapters that benefit from typedefs std::binary_function introduces. > > What wrappers, adapters and benefits are those? In addition to Igor's example, here's another adapter that I find useful, to automatically resolve pointers: template <class Predicate> struct binary_resolve_ptr : public std::binary_function < typename const Predicate::first_argument_type*, typename const Predicate::second_argument_type*, bool > { bool operator()( const first_argument_type& arg1, const second_argument_type& arg2) const { return Predicate()(*arg1, *arg2); } }; This comes handy for searching or sorting containers of pointers, but it really shines in generic programming. Now let's suppose that you have a predicate not inherited from binary_function: template <class T> struct incorrect_less { bool operator()(const T& x, const T& y) const { return x < y; } }; You wouldn't be able to use binary_resolve_ptr<incorrect_less<T>>. Nevertheless, you could use incorrect_less for years without ever noticing any problems with it in your own code. Tom |