Skip to content

Commit

Permalink
Improve binding.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Oct 23, 2019
1 parent e0944b3 commit fe0519a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/tao/json/binding/constant.hpp
Expand Up @@ -23,6 +23,8 @@ namespace tao::json::binding
template< bool V >
struct element_b
{
using value_t = bool;

template< typename C >
[[nodiscard]] static bool read( const C& /*unused*/ )
{
Expand Down Expand Up @@ -57,6 +59,8 @@ namespace tao::json::binding
template< std::int64_t V >
struct element_i
{
using value_t = std::int64_t;

template< typename C >
[[nodiscard]] static std::int64_t read( const C& /*unused*/ )
{
Expand Down Expand Up @@ -91,6 +95,8 @@ namespace tao::json::binding
template< std::uint64_t V >
struct element_u
{
using value_t = std::uint64_t;

template< typename C >
[[nodiscard]] static std::uint64_t read( const C& /*unused*/ )
{
Expand Down Expand Up @@ -128,6 +134,8 @@ namespace tao::json::binding
template< char... Cs >
struct element_s< json::internal::string_t< Cs... > >
{
using value_t = std::string; // TODO: Or std::string_view? Something else? Nothing?

using string = json::internal::string_t< Cs... >;

template< typename C >
Expand Down
2 changes: 2 additions & 0 deletions include/tao/json/binding/element.hpp
Expand Up @@ -60,6 +60,7 @@ namespace tao::json::binding
struct element< T C::*, P, std::enable_if_t< std::is_member_function_pointer_v< T C::* > > >
{
using class_t = C;
using value_t = T;

using internal_t = std::decay_t< decltype( ( std::declval< const C >().*P )() ) >;

Expand All @@ -79,6 +80,7 @@ namespace tao::json::binding
struct element< T ( * )( const C& ), P >
{
using class_t = C;
using value_t = T;

[[nodiscard]] static decltype( auto ) read( const C& v )
{
Expand Down
2 changes: 1 addition & 1 deletion include/tao/json/binding/internal/array.hpp
Expand Up @@ -34,7 +34,7 @@ namespace tao::json::binding::internal
}

template< template< typename... > class Traits, typename C >
static C as_type( const basic_value< Traits >& v ) // TODO: std::enable_if_t< WHAT?, C >
static std::enable_if_t< std::is_constructible_v< C, typename As::value_t... >, C > as_type( const basic_value< Traits >& v )
{
const auto& a = get_array_impl< Traits, C >( v );
return C( a[ Is ].template as< typename As::value_t >()... );
Expand Down

0 comments on commit fe0519a

Please sign in to comment.