#ifndef ALGO_COMMON_H #define ALGO_COMMON_H namespace algo { struct _nil { }; struct _one { char c[1]; }; struct _two { char c[2]; }; template struct tmpl_if; template struct tmpl_if { typedef Then result; }; template struct tmpl_if { typedef Else result; }; template struct traits { enum { REF = false, CONST = false }; typedef T orig_t; typedef T type_t; typedef T& ref_t; typedef T b_orig_t; typedef T b_type_t; typedef T& b_ref_t; typedef const T c_orig_t; typedef const T c_type_t; typedef const T& c_ref_t; }; template struct traits { enum { REF = true, CONST = false }; typedef T& orig_t; typedef T type_t; typedef T& ref_t; typedef T& b_orig_t; typedef T b_type_t; typedef T& b_ref_t; typedef const T& c_orig_t; typedef const T c_type_t; typedef const T& c_ref_t; }; template struct traits { enum { REF = false, CONST = true }; typedef const T orig_t; typedef const T type_t; typedef const T& ref_t; typedef T b_orig_t; typedef T b_type_t; typedef T& b_ref_t; typedef const T c_orig_t; typedef const T c_type_t; typedef const T& c_ref_t; }; template struct traits { enum { REF = true, CONST = true }; typedef const T& orig_t; typedef const T type_t; typedef const T& ref_t; typedef T& b_orig_t; typedef T b_type_t; typedef T& b_ref_t; typedef const T& c_orig_t; typedef const T c_type_t; typedef const T& c_ref_t; }; // Helper function used to generate an instantated type for typeof // calls. template T _makeT(); template struct _op_assign; // This class acts like a wrapper identifying classes that // are compatible with the algo structure. template struct _wrapper { template struct _ { typedef typeof(_makeT()(_makeT())) return_t; }; _wrapper(Ftor ftor) : m_ftor(ftor) {} template typename _::return_t operator () (Arg0& arg0 = _nil()) { return m_ftor(arg0); } // template // typename _::return_t operator () (const Arg0& arg0) { // return m_ftor(arg0); // } template inline _wrapper<_op_assign > operator = (_wrapper w) { return make_wrapper(_op_assign(m_ftor, w.m_ftor)); } Ftor m_ftor; }; template inline _wrapper make_wrapper(Ftor ftor) { return _wrapper(ftor); } } #endif