Hello,
I have a small problem. Some of my data holders have dereference operator
which returns refernces to contained types. The problem I face here is that
I have some noncopyable types and the dereference operator fails to compile.
I thought using a reference_wrapper class could do the trick, but then I can
not call functions on the contained type without explict casting, regardless
operator T&() const defined.
here is a small test app to simulate the behavior:
#include
#include
#include
using namespace std;
template<class T>
struct test
{
test() : ptr(new T())
{}
~test()
{
delete ptr;
}
boost::reference_wrapper<T> operator*()
{
return boost::ref(*ptr);
}
T* ptr;
};
template
class array : public boost::array
, private boost::noncopyable
{};
int main(int argc, char* argv[])
{
test< array > t;
int size = (static_cast&>(*t)).size();
}
Is there any way to call the last line like:
int size = (*t).size();
operator ->() would work just fine, but I need to support both.
Thanks for help,
Ovanes Markarian