refs #311 added initializer_list constructors in containers

This commit is contained in:
Mathew Sutcliffe
2014-08-01 20:22:51 +01:00
parent 58318677b5
commit d6234ee2cd
4 changed files with 35 additions and 1 deletions

View File

@@ -15,9 +15,20 @@
#include <algorithm>
#include <type_traits>
#include <iterator>
#include <initializer_list>
namespace BlackMisc
{
namespace Private
{
// Trait to exclude std::initializer_list from the overload set of CRange conversion operators using SFINAE.
// Needed to workaround a bug in MSVC whereby it considers the copy constructor and initializer list constructor
// of a container to be ambiguous when converting from a CRange.
//! \private
template <class T> struct is_initializer_list : public std::false_type {};
//! \private
template <class T> struct is_initializer_list<std::initializer_list<T>> : public std::true_type {};
}
template <class> class CRange;
@@ -135,7 +146,8 @@ namespace BlackMisc
//! @}
//! Implicit conversion to any container of value_type which supports push_back. This will copy elements.
template <class T, class = typename std::enable_if<std::is_convertible<value_type, typename T::value_type>::value>::type>
template <class T, class = typename std::enable_if<! Private::is_initializer_list<T>::value &&
std::is_convertible<value_type, typename T::value_type>::value>::type>
operator T() const
{
T container;