Boost Reflect Library 0.1.0
void.hpp
Go to the documentation of this file.
00001 #ifndef __BOOST_REFLECT_VOID_HPP
00002 #define __BOOST_REFLECT_VOID_HPP
00003 #include <iostream>
00004 
00005 namespace boost { namespace reflect {
00006     /**
00007      * @brief A type to replace void in generic code.
00008      *
00009      * void cannot be treated like any other type and thus always introduces
00010      * many 'special cases' to generic code.  This type is used in generic code any
00011      * all functors that return void can be adapted to return void_t before being
00012      * used with generic code via boost::reflect::adapt_void.
00013      */
00014     struct void_t{
00015         friend std::ostream& operator<<(std::ostream& os,const void_t&) {return os;}
00016         friend std::istream& operator>>(std::istream& is,void_t&)       {return is;}
00017     };
00018 
00019     /**
00020      *  @brief Converts functors returning void to functors returning \link 
00021                boost::refelct::void_t void_t   \link
00022 
00023      *  Generic code that deals with functions returning void is a special case
00024      *  that requires many work arounds.  This class adapts a void(FusionSeq) functor
00025      *  into a void_t(FusionSeq) functor.
00026      */
00027     template<typename R, typename Functor=int>
00028     struct adapt_void {
00029         typedef R result_type;
00030 
00031         adapt_void( const Functor _f):f(_f){}
00032 
00033         template<typename Seq>
00034         result_type operator()( const Seq& seq )const {
00035             return f(seq);
00036         }
00037         template<typename Seq>
00038         result_type operator()( Seq& seq )const {
00039             return f(seq);
00040         }
00041         Functor f;
00042     };
00043     #ifndef DOXYGEN
00044     template<typename Functor>
00045     struct adapt_void<void,Functor> {
00046         typedef void_t result_type;
00047         adapt_void( const Functor _f):f(_f){}
00048 
00049         template<typename Seq>
00050         result_type operator()( const Seq& seq )const {
00051             f(seq); return result_type();
00052         }
00053         template<typename Seq>
00054         result_type operator()( Seq& seq )const {
00055             f(seq); return result_type();
00056         }
00057         Functor f;
00058     };
00059     #endif
00060 } }
00061 
00062 #endif

© Daniel Larimer 2010-2011 - Licensed under Boost Software License, Version 1.0 Boost Reflect Library