mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-17 17:24:33 +00:00
fix(Core/Misc): few improvements to ut8 handling (#2455)
This commit is contained in:
@@ -8,6 +8,10 @@
|
||||
#define ACORE_CONTAINERS_H
|
||||
|
||||
#include "Define.h"
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <list>
|
||||
|
||||
//! Because circular includes are bad
|
||||
@@ -15,6 +19,46 @@ extern uint32 urand(uint32 min, uint32 max);
|
||||
|
||||
namespace acore
|
||||
{
|
||||
template<class T>
|
||||
constexpr inline T* AddressOrSelf(T* ptr)
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
constexpr inline T* AddressOrSelf(T& not_ptr)
|
||||
{
|
||||
return std::addressof(not_ptr);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
class CheckedBufferOutputIterator
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::output_iterator_tag;
|
||||
using value_type = void;
|
||||
using pointer = T*;
|
||||
using reference = T&;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
|
||||
CheckedBufferOutputIterator(T* buf, size_t n) : _buf(buf), _end(buf+n) {}
|
||||
|
||||
T& operator*() const { check(); return *_buf; }
|
||||
CheckedBufferOutputIterator& operator++() { check(); ++_buf; return *this; }
|
||||
CheckedBufferOutputIterator operator++(int) { CheckedBufferOutputIterator v = *this; operator++(); return v; }
|
||||
|
||||
size_t remaining() const { return (_end - _buf); }
|
||||
|
||||
private:
|
||||
T* _buf;
|
||||
T* _end;
|
||||
void check() const
|
||||
{
|
||||
if (!(_buf < _end))
|
||||
throw std::out_of_range("index");
|
||||
}
|
||||
};
|
||||
|
||||
namespace Containers
|
||||
{
|
||||
template<class T>
|
||||
|
||||
Reference in New Issue
Block a user