mirror of https://github.com/catchorg/Catch2.git
Fix MSVC compilation error
MSVC's `std::vector` requires its allocator to have copy constructor from the same allocator kind, but templated over different type.
This commit is contained in:
parent
b245eaa7d1
commit
53864dee7b
|
@ -27,8 +27,14 @@ namespace {
|
||||||
/* Minimal Allocator */
|
/* Minimal Allocator */
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct minimal_allocator {
|
struct minimal_allocator {
|
||||||
typedef T value_type;
|
using value_type = T;
|
||||||
typedef std::size_t size_type;
|
using size_type = std::size_t;
|
||||||
|
|
||||||
|
minimal_allocator() = default;
|
||||||
|
template <typename U>
|
||||||
|
minimal_allocator(const minimal_allocator<U>&) {}
|
||||||
|
|
||||||
|
|
||||||
T *allocate( size_type n ) {
|
T *allocate( size_type n ) {
|
||||||
return static_cast<T *>( ::operator new( n * sizeof(T) ) );
|
return static_cast<T *>( ::operator new( n * sizeof(T) ) );
|
||||||
}
|
}
|
||||||
|
@ -52,8 +58,8 @@ TEST_CASE( "vector<int,allocator> -> toString", "[toString][vector,allocator][c+
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "vec<vec<string,alloc>> -> toString", "[toString][vector,allocator][c++11][.]" ) {
|
TEST_CASE( "vec<vec<string,alloc>> -> toString", "[toString][vector,allocator][c++11][.]" ) {
|
||||||
typedef std::vector<std::string,minimal_allocator<std::string> > inner;
|
using inner = std::vector<std::string, minimal_allocator<std::string>>;
|
||||||
typedef std::vector<inner> vector;
|
using vector = std::vector<inner>;
|
||||||
vector v;
|
vector v;
|
||||||
REQUIRE( Catch::toString(v) == "{ }" );
|
REQUIRE( Catch::toString(v) == "{ }" );
|
||||||
v.push_back( inner { "hello" } );
|
v.push_back( inner { "hello" } );
|
||||||
|
|
Loading…
Reference in New Issue