"Typedef" for the template function (boost :: make_shared)

I am porting my project to C ++ 11, and I try to use as much of the standard library as possible.

Before completing the migration, I need a quick way to flip between boost and the STL implementation of shared_ptr (to run tests, unit tests, etc.).

So, I defined an alias for shared_ptr as follows:

 #ifdef _USE_BOOST_ template <class C> using shared_ptr = boost::shared_ptr<C> #else template <class C> using shared_ptr = std::shared_ptr<C> #endif 

now i need to do the same for make_shared ... But how? Macro? Wrapper? I don’t really like it. What are the alternatives?

+6
source share
1 answer

Using variable templates and flawless redirects:

 template<typename C, typename...Args> shared_ptr<C> make_shared(Args &&...args) { #ifdef _USE_BOOST_ return boost::make_shared<C>(std::forward<Args>(args)...); #else return std::make_shared<C>(std::forward<Args>(args)...); #endif } 
+7
source

All Articles