
Jeffrey Lee Hellrung, Jr. wrote:
What do you think about using the templated constructor *and* SFINAE out via enable_if the binding of U to initialized<T> (or, maybe, to any class derived from initialized<T>)?
SFINAE/enable_if might be interesting indeed, but I'm not sure if it's really necessary. And I don't think it will help to work around the specific MSVC bug <http://connect.microsoft.com/VisualStudio/feedback/details/423737>. Here is an example that fails to compile on MSVC because of the compiler bug. Please let me know if you can fix it by SFINAE. (But I'm afraid it won't work.) ////////////////////////////////////////////////// namespace boost { template<class T> class initialized { T m_data; public: initialized() : m_data() { } initialized(const initialized& arg) : m_data(arg.m_data) { } template<class U> explicit initialized(const U& arg) : m_data(arg) { } operator T&() { return m_data; } operator const T&() const { return m_data; } }; } ////////////////////////////////////////////////// // USER CODE STARTS HERE class my_initialized_int: boost::initialized<int> { }; int main() { my_initialized_int i1; my_initialized_int i2 = i1; } ////////////////////////////////////////////////// The example above compiles well on Comeau 4.3.10.1 <www.comeaucomputing.com/tryitout> and GCC 4.1.2 <http://codepad.org/NCZKJ3OE>. But it fails on MSVC, as www.dinkumware.com/exam says: error C2247: 'boost::initialized<T>::operator const int &' not accessible because 'my_initialized_int' uses 'private' to inherit from 'boost::initialized<T>' Would boost::initialized<T> really need to have a /templated/ constructor, initialized(const U&)? Wouldn't a non-templated initialized(const T&) be sufficient, for initialized<T>? Note that that's just what Edward was asking for <https://svn.boost.org/trac/boost/ticket/3472>. Do you have a motivating use case for a templated constructor of initialized<T>? Anyway, I /do/ think that it would be useful to add move semantics, by adding a initialized(T&&) constructor, for those compilers that support rvalue references. Kind regards, Niels -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center