mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 00:46:03 +08:00
Added experimental uni_type
This commit is contained in:
parent
67c19bb0dc
commit
84e1241c39
78
include/etl/experimental/uni_type.h
Normal file
78
include/etl/experimental/uni_type.h
Normal file
@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
template <size_t Size_>
|
||||
class uni_type
|
||||
{
|
||||
public:
|
||||
|
||||
static constexpr size_t Size = Size_;
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
T& get()
|
||||
{
|
||||
return *reinterpret_cast<T*>(buffer);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
const T& get() const
|
||||
{
|
||||
return *reinterpret_cast<T*>(buffer);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
operator T()
|
||||
{
|
||||
return *reinterpret_cast<T*>(buffer);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
constexpr size_t size() const
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
char buffer[Size]
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <size_t Size_>
|
||||
class uni_type_ptr
|
||||
{
|
||||
public:
|
||||
|
||||
static constexpr size_t Size = Size_;
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
T& get()
|
||||
{
|
||||
return *reinterpret_cast<T*>(pbuffer);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
template <typename T>
|
||||
const T& get() const
|
||||
{
|
||||
return *reinterpret_cast<T*>(pbuffer);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
operator T()
|
||||
{
|
||||
return *reinterpret_cast<T*>(pbuffer);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
constexpr size_t size() const
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
char* pbuffer;
|
||||
};
|
||||
@ -1309,6 +1309,7 @@
|
||||
<ClInclude Include="..\..\include\etl\cumulative_moving_average.h" />
|
||||
<ClInclude Include="..\..\include\etl\delegate.h" />
|
||||
<ClInclude Include="..\..\include\etl\delegate_service.h" />
|
||||
<ClInclude Include="..\..\include\etl\experimental\uni_type.h" />
|
||||
<ClInclude Include="..\..\include\etl\file_error_numbers.h" />
|
||||
<ClInclude Include="..\..\include\etl\flags.h" />
|
||||
<ClInclude Include="..\..\include\etl\format_spec.h" />
|
||||
|
||||
@ -106,6 +106,9 @@
|
||||
<Filter Include="Source Files\Scripts">
|
||||
<UniqueIdentifier>{562466b5-677d-4448-9e9e-f70805cd71ad}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="ETL\Experimental">
|
||||
<UniqueIdentifier>{79c578f6-5400-4b4d-b2a4-9a8c589f7c81}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\etl\enum_type.h">
|
||||
@ -1107,6 +1110,9 @@
|
||||
<ClInclude Include="..\..\include\etl\private\variant_new.h">
|
||||
<Filter>ETL\Private</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\experimental\uni_type.h">
|
||||
<Filter>ETL\Experimental</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\main.cpp">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user