Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 48486a57d7 |
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "tl/functional.h"
|
||||||
|
|
||||||
|
namespace tl
|
||||||
|
{
|
||||||
|
class epilogue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
epilogue(function<void()> i_function) noexcept
|
||||||
|
: m_function(std::move(i_function))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~epilogue() noexcept
|
||||||
|
{
|
||||||
|
m_function();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
function<void()> m_function;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
+16
-13
@@ -7,43 +7,46 @@
|
|||||||
namespace tl
|
namespace tl
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename T, typename Tag>
|
template<typename T, T invalid_value, typename Tag>
|
||||||
struct identifier
|
struct identifier
|
||||||
{
|
{
|
||||||
using underlying_type = T;
|
using underlying_type = T;
|
||||||
|
|
||||||
identifier() = delete;
|
constexpr identifier() noexcept = default;
|
||||||
explicit constexpr identifier(T value) noexcept : m_value(std::move(value)) {}
|
explicit constexpr identifier(T value) noexcept : m_value(std::move(value)) {}
|
||||||
|
|
||||||
constexpr T value() const noexcept { return m_value; }
|
constexpr T value() const noexcept { return m_value; }
|
||||||
auto operator<=>(const identifier<T, Tag>& other) const noexcept { return m_value <=> other.value(); }
|
constexpr bool is_valid() const noexcept { return m_value != invalid_value; }
|
||||||
|
//inline static identifier<T, invalid_value, Tag> invalid() noexcept { return identifier<T, invalid_value, Tag>(); }
|
||||||
|
|
||||||
|
auto operator<=>(const identifier<T, invalid_value, Tag>& other) const noexcept { return m_value <=> other.value(); }
|
||||||
auto operator<=>(const T& other) const noexcept { return m_value <=> other; }
|
auto operator<=>(const T& other) const noexcept { return m_value <=> other; }
|
||||||
bool operator==(const identifier<T, Tag>& other) const noexcept { return m_value == other.value(); }
|
bool operator==(const identifier<T, invalid_value, Tag>& other) const noexcept { return m_value == other.value(); }
|
||||||
bool operator==(const T& other) const noexcept { return m_value == other; }
|
bool operator==(const T& other) const noexcept { return m_value == other; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T m_value;
|
T m_value = invalid_value;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TL_DECLARE_INTEGRAL_ID(NAME, TYPE) \
|
#define TL_DECLARE_INTEGRAL_ID(NAME, TYPE, INVALID_VALUE) \
|
||||||
struct NAME##_tag {};\
|
struct NAME##_tag {};\
|
||||||
using NAME = tl::identifier<TYPE, NAME##_tag>;
|
using NAME = tl::identifier<TYPE, INVALID_VALUE, NAME##_tag>;
|
||||||
|
|
||||||
template <typename T, typename Tag>
|
template <typename T, T invalid_value, typename Tag>
|
||||||
struct std::formatter<tl::identifier<T, Tag>>
|
struct std::formatter<tl::identifier<T, invalid_value, Tag>>
|
||||||
{
|
{
|
||||||
constexpr auto parse(format_parse_context& ctx) noexcept { return ctx.begin(); }
|
constexpr auto parse(format_parse_context& ctx) noexcept { return ctx.begin(); }
|
||||||
auto format(const tl::identifier<T, Tag>& id, std::format_context& ctx) const
|
auto format(const tl::identifier<T, invalid_value, Tag>& id, std::format_context& ctx) const
|
||||||
{
|
{
|
||||||
return format_to(ctx.out(), "{}", id.value());
|
return format_to(ctx.out(), "{}", id.value());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, typename Tag>
|
template<typename T, T invalid_value, typename Tag>
|
||||||
struct eastl::hash<tl::identifier<T, Tag>>
|
struct eastl::hash<tl::identifier<T, invalid_value, Tag>>
|
||||||
{
|
{
|
||||||
size_t operator()(tl::identifier<T, Tag> const& id) const
|
size_t operator()(tl::identifier<T, invalid_value, Tag> const& id) const
|
||||||
{
|
{
|
||||||
return hash<T>()(id.value());
|
return hash<T>()(id.value());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define TL_ONLY_IN_DEBUG(...) __VA_ARGS__
|
|
||||||
#else
|
|
||||||
#define TL_ONLY_IN_DEBUG(...)
|
|
||||||
#endif
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<NonUserCode xmlns="http://schemas.microsoft.com/vstudio/debugger/jmc/2013">
|
<NonUserCode xmlns="http://schemas.microsoft.com/vstudio/debugger/jmc/2013">
|
||||||
<File Name="*\tl\*" />
|
<File Name="*\jtl\*" />
|
||||||
</NonUserCode>
|
</NonUserCode>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<StepFilter xmlns="http://schemas.microsoft.com/vstudio/debugger/natstepfilter/2010">
|
<StepFilter xmlns="http://schemas.microsoft.com/vstudio/debugger/natstepfilter/2010">
|
||||||
<Function><Name>tl::.*</Name><Action>NoStepInto</Action></Function>
|
<Function><Name>jtl::.*</Name><Action>NoStepInto</Action></Function>
|
||||||
</StepFilter>
|
</StepFilter>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user