Skip to content

Commit 6b124b6

Browse files
authored
Merge pull request #25 from RaisinTen/use-forward-in-construct.hpp
Use variadic templates to get rid of manual overloads in construct.hpp
2 parents 40b6f20 + 568a4d2 commit 6b124b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

include/boost/lambda/construct.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "boost/type_traits/remove_cv.hpp"
1818
#include "boost/type_traits/is_pointer.hpp"
1919

20+
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
21+
#include <utility>
22+
#endif
23+
2024
namespace boost {
2125
namespace lambda {
2226

@@ -28,6 +32,12 @@ template<class T> struct constructor {
2832

2933
template <class U> struct sig { typedef T type; };
3034

35+
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
36+
template <class... Args>
37+
T operator()(Args&&... args) const {
38+
return T(std::forward<Args>(args)...);
39+
}
40+
#else
3141
T operator()() const {
3242
return T();
3343
}
@@ -81,6 +91,7 @@ template<class T> struct constructor {
8191
T operator()(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8, A9& a9, A10& a10) const {
8292
return T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
8393
}
94+
#endif
8495

8596
};
8697

@@ -137,6 +148,12 @@ template<class T> struct new_ptr {
137148

138149
template <class U> struct sig { typedef T* type; };
139150

151+
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
152+
template <class... Args>
153+
T* operator()(Args&&... args) const {
154+
return new T(std::forward<Args>(args)...);
155+
}
156+
#else
140157
T* operator()() const {
141158
return new T();
142159
}
@@ -190,6 +207,7 @@ template<class T> struct new_ptr {
190207
T* operator()(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7, A8& a8, A9& a9, A10& a10) const {
191208
return new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
192209
}
210+
#endif
193211

194212
};
195213

0 commit comments

Comments
 (0)