Compare commits
No commits in common. "6ba83fd582e2ac61ab3e8acdc62eb38ccbe4920f" and "ec70a5bba16c2e4fc610103a0250b37fb991eda0" have entirely different histories.
6ba83fd582
...
ec70a5bba1
@ -2,14 +2,10 @@
|
|||||||
#define CONST_FMT_STD_LIB_H
|
#define CONST_FMT_STD_LIB_H
|
||||||
|
|
||||||
|
|
||||||
#ifndef CONST_FMT_NO_CPP_STD_LIB
|
#ifdef CONST_FMT_NO_STD_LIB
|
||||||
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
@ -18,98 +14,46 @@ namespace std {
|
|||||||
using size_t = uint16_t;
|
using size_t = uint16_t;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* type_traits
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
template<typename T> struct remove_reference { using type = T; };
|
|
||||||
template<typename T> struct remove_reference<T&> { using type = T; };
|
|
||||||
template<typename T> struct remove_reference<T&&> { using type = T; };
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using remove_reference_t = typename std::remove_reference<T>::type;
|
|
||||||
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* utility
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::remove_reference_t<T>&& move(T&& arg) noexcept {
|
|
||||||
return reinterpret_cast<std::remove_reference_t<T>&&>(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void swap(T& t1, T& t2) {
|
|
||||||
T temp = std::move(t1);
|
|
||||||
t1 = std::move(t2);
|
|
||||||
t2 = std::move(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* std::array
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Is std::size_t really the best bet here?
|
// TODO: Is std::size_t really the best bet here?
|
||||||
template <typename data_t, std::size_t t_size>
|
template <typename data_t, std::size_t t_size>
|
||||||
class array {
|
class array {
|
||||||
public:
|
public:
|
||||||
template<typename... args_t>
|
// Constructors
|
||||||
constexpr array(args_t... args) noexcept : m_data{args...} {
|
|
||||||
static_assert(sizeof...(args) == t_size, "Invalid number of arguments");
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr array() noexcept = default;
|
array() = default;
|
||||||
constexpr array(array&) = default;
|
array(const array& other) = default;
|
||||||
constexpr array(array&&) = default;
|
array(array&& other) = default;
|
||||||
|
|
||||||
constexpr array& operator=(array& other) = default;
|
// Operators
|
||||||
constexpr array& operator=(array&& other) = default;
|
|
||||||
|
|
||||||
constexpr void swap(array<data_t, t_size>& other) noexcept {
|
array operator=(const array& other) = default;
|
||||||
for (int i = 0; i < t_size; ++i) {
|
array operator=(array&& other) = default;
|
||||||
using std::swap;
|
|
||||||
swap(m_data[i], other.m_data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Element access
|
||||||
|
|
||||||
constexpr data_t& operator[](std::size_t index) noexcept {
|
data_t& operator[](std::size_t index) {
|
||||||
return m_data[index];
|
return m_data[index];
|
||||||
}
|
}
|
||||||
constexpr const data_t& operator[](std::size_t index) const noexcept {
|
const data_t& operator[](std::size_t index) const {
|
||||||
return m_data[index];
|
return m_data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterators
|
||||||
|
|
||||||
using iterator = data_t*;
|
using iterator = data_t*;
|
||||||
using const_iterator = const data_t*;
|
using const_iterator = const data_t*;
|
||||||
|
|
||||||
constexpr iterator begin() noexcept {
|
iterator begin() {
|
||||||
return &(m_data[0]);
|
return &(m_data[0]);
|
||||||
}
|
}
|
||||||
constexpr iterator end() noexcept {
|
iterator end() {
|
||||||
return (&(m_data[t_size-1]) + 1);
|
return (&(m_data[t_size-1]) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const_iterator cbegin() const noexcept {
|
const iterator cbegin() const {
|
||||||
return &(m_data[0]);
|
return &(m_data[0]);
|
||||||
}
|
}
|
||||||
constexpr const_iterator cend() const noexcept {
|
const iterator cend() const {
|
||||||
return (&(m_data[t_size-1]) + 1);
|
return (&(m_data[t_size-1]) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,7 @@
|
|||||||
#define LOGGER_TYPES_H
|
#define LOGGER_TYPES_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include "std_lib.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace const_fmt { namespace const_fmt_detail {
|
namespace const_fmt { namespace const_fmt_detail {
|
||||||
@ -20,8 +19,8 @@ template <std::size_t N>
|
|||||||
class ConstString {
|
class ConstString {
|
||||||
public:
|
public:
|
||||||
constexpr ConstString(const char (&content)[N]) noexcept {
|
constexpr ConstString(const char (&content)[N]) noexcept {
|
||||||
std::copy(&content[0], (&content[N-1] + 1),
|
std::copy(std::begin(content), std::end(content),
|
||||||
m_content.begin());
|
std::begin(m_content));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr char operator[](std::size_t index) const noexcept {
|
constexpr char operator[](std::size_t index) const noexcept {
|
||||||
|
|||||||
@ -2,9 +2,8 @@
|
|||||||
#define LOGGER_UTILITY_H
|
#define LOGGER_UTILITY_H
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
#include "std_lib.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user