remove std::cout
This commit is contained in:
parent
4a08806397
commit
8bbece686d
@ -262,60 +262,64 @@ TEST_CASE("bad my_allocator::construct")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace{
|
namespace
|
||||||
template <class T>
|
{
|
||||||
struct NAlloc {
|
template <class T>
|
||||||
// Aliases and inner types
|
struct NAlloc
|
||||||
using value_type = T;
|
{
|
||||||
using size_type = std::size_t;
|
// Aliases and inner types
|
||||||
using difference_type = ptrdiff_t;
|
using value_type = T;
|
||||||
using reference = value_type&;
|
using size_type = std::size_t;
|
||||||
using const_reference = const value_type&;
|
using difference_type = ptrdiff_t;
|
||||||
using pointer = value_type*;
|
using reference = value_type&;
|
||||||
using const_pointer = const value_type*;
|
using const_reference = const value_type&;
|
||||||
|
using pointer = value_type*;
|
||||||
|
using const_pointer = const value_type*;
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
struct rebind {
|
struct rebind
|
||||||
using other = NAlloc<U>;
|
{
|
||||||
};
|
using other = NAlloc<U>;
|
||||||
|
|
||||||
NAlloc() :
|
|
||||||
alloc() {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~NAlloc() { }
|
|
||||||
|
|
||||||
pointer allocate(std::size_t n) {
|
|
||||||
#ifdef _DEBUG
|
|
||||||
std::cout << "NAlloc allocating " << n << " bytes\n";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return static_cast<pointer>(alloc.allocate(n)); // get memory from pool
|
|
||||||
}
|
|
||||||
void deallocate(pointer p, [[maybe_unused]] std::size_t n) {
|
|
||||||
#ifdef _DEBUG
|
|
||||||
std::cout << "NAlloc deallocating " << n * sizeof *p << " bytes\n";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
alloc.deallocate(static_cast<pointer>(p), 1); // return memory to pool
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool operator!=(const NAlloc<T>& other) const {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
bool operator==(const NAlloc<T>& other) const {
|
|
||||||
return alloc == other.alloc;
|
|
||||||
}
|
|
||||||
|
|
||||||
my_allocator<char> alloc;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NAlloc() :
|
||||||
|
alloc()
|
||||||
|
{
|
||||||
|
|
||||||
using OstringStream = std::basic_ostringstream<char, std::char_traits<char>, NAlloc<char>>;
|
};
|
||||||
using IstringStream = std::basic_istringstream<char, std::char_traits<char>, NAlloc<char>>;
|
|
||||||
typedef std::basic_string<char, std::char_traits<char>, NAlloc<char>> RtString;
|
virtual ~NAlloc() { }
|
||||||
|
|
||||||
|
pointer allocate(std::size_t n)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return static_cast<pointer>(alloc.allocate(n)); // get memory from pool
|
||||||
|
}
|
||||||
|
void deallocate(pointer p, [[maybe_unused]] std::size_t n)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
alloc.deallocate(static_cast<pointer>(p), 1); // return memory to pool
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool operator!=(const NAlloc<T>& other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
bool operator==(const NAlloc<T>& other) const
|
||||||
|
{
|
||||||
|
return alloc == other.alloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
my_allocator<char> alloc;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
using OstringStream = std::basic_ostringstream<char, std::char_traits<char>, NAlloc<char>>;
|
||||||
|
using IstringStream = std::basic_istringstream<char, std::char_traits<char>, NAlloc<char>>;
|
||||||
|
typedef std::basic_string<char, std::char_traits<char>, NAlloc<char>> RtString;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user