문제

I made a class that has the same implementation of std::initializer_list using VS2013 that supports Uniform Initialization.

template <class _Elem>
class My_Initializer_List { ... } // Hope to replace std::initializer_list!

The first thing I've noticed is that the compiler keeps looking for std::initializer_list when it does have the substitute for it, which is My_Initiliazer_List.

void Foo()
{
    // The compiler tries to invoke 
    // its constructor with std::initializer<int>{ 10, 20 }.
    auto MyVar = My_Initializer_List<int>{ 10, 20 }; // Compile Error!
}

If this feature depends on the C++ Standard Library, then I believe that I should be able to replace it with my own class, at least for academic purposes.

Thanks in advance.

도움이 되었습니까?

해결책

Sorry, but no. The compiler has special knowledge of std::initializer_list "baked in". The same is true of a few other parts of the standard library (e.g., a dynamic_cast of a reference throws a std::bad_cast, and there's not really anything you can do to change that either).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top