make_pair can create pairs without mentioning the types. I want to use the same trick for my class, but it inherits from boost::noncopyable, so this does not compile:
template<class Iter>
struct bit_writer : boost:noncopyable
{
Iter iter;
bit_writer(Iter iter)
: iter(iter)
{}
};
template<class Iter>
bit_writer<Iter> make_bit_writer(Iter iter)
{
return bit_writer<Iter>(iter);
}
vector<char> vec;
auto w = make_bit_writer(vec);
Any alternative? I tried making make_bit_writer a friend, and then run out of ideas.
If you have C++11 you can do this using something like:
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.