Skip to content

Commit

Permalink
Use C++20 features
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Oct 27, 2024
1 parent 0859eb7 commit ded2923
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions include/tao/pq/binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,25 @@ namespace tao::pq
using binary = std::vector< std::byte >;
using binary_view = std::span< const std::byte >;

template< typename T >
[[nodiscard]] auto to_binary_view( const T* data, const std::size_t size ) noexcept -> binary_view
[[nodiscard]] auto to_binary_view( const auto* data, const std::size_t size ) noexcept -> binary_view
{
static_assert( sizeof( T ) == 1 );
static_assert( sizeof( *data ) == 1 );
return { reinterpret_cast< const std::byte* >( data ), size };
}

template< typename T >
[[nodiscard]] auto to_binary_view( const T& value ) noexcept -> binary_view
[[nodiscard]] auto to_binary_view( const auto& value ) noexcept -> binary_view
{
return pq::to_binary_view( std::data( value ), std::size( value ) );
}

template< typename T >
[[nodiscard]] auto to_binary( const T* data, const std::size_t size ) -> binary
[[nodiscard]] auto to_binary( const auto* data, const std::size_t size ) -> binary
{
static_assert( sizeof( T ) == 1 );
static_assert( sizeof( *data ) == 1 );
const auto* ptr = reinterpret_cast< const std::byte* >( data );
return { ptr, ptr + size };
}

template< typename T >
[[nodiscard]] auto to_binary( const T& value ) -> binary
[[nodiscard]] auto to_binary( const auto& value ) -> binary
{
return pq::to_binary( std::data( value ), std::size( value ) );
}
Expand Down

0 comments on commit ded2923

Please sign in to comment.