Skip to content

Commit

Permalink
[f-sweep-in-mult-pops] types - added a cosi-specific type converter i…
Browse files Browse the repository at this point in the history
…nfrastructure
  • Loading branch information
notestaff committed Feb 15, 2016
1 parent e02846a commit 2560ff9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cosi/general/utildefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <cstdio>
#include <sstream>
#include <string>
#include <boost/core/enable_if.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/filesystem.hpp>

namespace cosi {
Expand Down Expand Up @@ -63,6 +65,21 @@ typedef boost::filesystem::path filename_t;
return fopen( s.c_str(), mode );
}

template <typename TFrom, typename TTo, typename Enable=void> struct cosi_converter: public boost::false_type { };

template <typename TTo, typename TFrom>
typename boost::enable_if< cosi_converter<TFrom,TTo>, TTo>::type cosi_cvt( TFrom x ) {
return cosi_converter<TFrom,TTo>()( x );
}

template <typename TFrom, typename TTo>
struct cosi_converter<TFrom,TTo,
typename boost::enable_if< boost::is_convertible<TFrom,TTo> >::type >: public boost::true_type {
TTo operator()( TFrom const& x ) const { return static_cast<TTo>( x ); }
};

// use boost TTI to test for existence of this expression? check for limitations

} // namespace cosi

#endif // #ifndef COSI_INCLUDE_UTILDEFS_H

0 comments on commit 2560ff9

Please sign in to comment.