If you have C++11 you can do this using something like:
#include <functional>
#include <utility>
#include <type_traits>
struct noncopyable_but_still_moveable {
noncopyable_but_still_moveable(const noncopyable_but_still_moveable&) = delete;
noncopyable_but_still_moveable(noncopyable_but_still_moveable&&) = default;
noncopyable_but_still_moveable() = default;
noncopyable_but_still_moveable& operator=(const noncopyable_but_still_moveable&) = default;
noncopyable_but_still_moveable& operator=(noncopyable_but_still_moveable&&) = default;
};
template <typename T>
struct test : noncopyable_but_still_moveable {
test(T) {}
// the rest is irrelevant
};
template <typename T>
test<T> make_test(T&& val) {
return test<typename std::remove_reference<T>::type>(std::forward<T>(val));
}
int main() {
auto && w = make_test(0);
}
Note that I've replaced boost::noncopyable
with a type that has a deleted copy constructor. This is the C++11 way of making something non-copyable and is needed because the boost class was also not moveable. Of course you could just put that inside the class itself and not inherit any more.
Without C++11 you'll want to use something like Boost move to emulate these semantics.