C++ wrapper for boost/c++11 -


i not sure title of question proper. here problem. writing library use c++11 library features. not implementations support these libraries yet , there portability problem. not matter library of concern here. 1 solution use boost, provide lot c++11 libraries. solution define macro, use_cxx11, , define new namespace internal , introduce names internal namespace dependent on macros. example need use name foo c++ library <foo>, available in <boost/foo/foo.hpp>. is

#ifdef use_cxx11 #include <foo> #else #include <boost/foo/foo.hpp> #endif  namespace internal { #ifdef use_cxx11 using std::foo; #else using boost::foo::foo; #endif } 

and in rest of library use internal::foo. third party code use library can define proper macro indicate if have working c++ 11 implementation or can use boost. , library pickup right header , namespace. works far. hope have explained intention well.

but above solutions seems ugly me. there better practice kind of thing? or there possible situations approach not work?

your solution looks fine me; problem (as chet mentions) in cases boost , c++11 interfaces and/or implementations differ.

in fact, in boost.algorithms library (new in upcoming 1.50 release)

namespace boost { namespace algorithm { #if __cplusplus >= 201103l using std::find_if_not;      // section 25.2.5 #else template<typename inputiterator, typename predicate>  inputiterator find_if_not ( inputiterator first, inputiterator last, predicate p ) {     ( ; first != last; ++first )         if ( !p(*first))             break;     return first; } #endif }} 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -