fix(Core/Misc): few improvements to ut8 handling (#2455)

This commit is contained in:
Viste
2019-12-02 10:33:44 +03:00
committed by Stoabrogga
parent ad320ec9d9
commit ec808793ae
11 changed files with 200 additions and 94 deletions

View File

@@ -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>