Add rjp::cast specialization for rvalue To type. Acts as a std::move equivalent
This commit is contained in:
parent
ed6e15db6e
commit
ee0a1d48da
@ -22,7 +22,7 @@
|
|||||||
#include <rjp.h>
|
#include <rjp.h>
|
||||||
#include "integral.hpp"
|
#include "integral.hpp"
|
||||||
|
|
||||||
namespace rjp::detail{
|
namespace rjp{
|
||||||
namespace detail{
|
namespace detail{
|
||||||
template<class To, class From, bool = std::is_same<std::remove_reference_t<To>,std::remove_reference_t<From>>::value>
|
template<class To, class From, bool = std::is_same<std::remove_reference_t<To>,std::remove_reference_t<From>>::value>
|
||||||
struct convert_helper;
|
struct convert_helper;
|
||||||
@ -64,6 +64,14 @@ namespace rjp::detail{
|
|||||||
struct get_ref<To, From&&>{
|
struct get_ref<To, From&&>{
|
||||||
using type = std::remove_reference_t<To>&&;
|
using type = std::remove_reference_t<To>&&;
|
||||||
};
|
};
|
||||||
|
template<class To, class From>
|
||||||
|
struct get_ref<To&&, From&>{
|
||||||
|
using type = To&&;
|
||||||
|
};
|
||||||
|
template<class To, class From>
|
||||||
|
struct get_ref<To&&, From&&>{
|
||||||
|
using type = To&&;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class To, class From>
|
template<class To, class From>
|
||||||
@ -71,14 +79,16 @@ namespace rjp::detail{
|
|||||||
return static_cast<typename detail::get_ref<To,From&&>::type>(std::forward<From>(from));
|
return static_cast<typename detail::get_ref<To,From&&>::type>(std::forward<From>(from));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Val>
|
namespace detail{
|
||||||
void set_to_underlying(RJP_value* val, typename Val::underlying_type);
|
template<class Val>
|
||||||
template<>
|
void set_to_underlying(RJP_value* val, typename Val::underlying_type);
|
||||||
void set_to_underlying<rjp::integer>(RJP_value* val, RJP_int i);
|
template<>
|
||||||
template<>
|
void set_to_underlying<rjp::integer>(RJP_value* val, RJP_int i);
|
||||||
void set_to_underlying<rjp::dfloat>(RJP_value* val, RJP_float f);
|
template<>
|
||||||
template<>
|
void set_to_underlying<rjp::dfloat>(RJP_value* val, RJP_float f);
|
||||||
void set_to_underlying<rjp::boolean>(RJP_value* val, RJP_bool b);
|
template<>
|
||||||
|
void set_to_underlying<rjp::boolean>(RJP_value* val, RJP_bool b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -35,14 +35,14 @@ rjp::value case_6(void){
|
|||||||
rjp::value case_8(void){
|
rjp::value case_8(void){
|
||||||
rjp::object obj;
|
rjp::object obj;
|
||||||
obj.add<rjp::integer>("key"_ss, 7);
|
obj.add<rjp::integer>("key"_ss, 7);
|
||||||
return std::move(obj);
|
return rjp::cast<rjp::value&&>(obj);
|
||||||
}
|
}
|
||||||
//handle object with subobject
|
//handle object with subobject
|
||||||
rjp::value case_9(void){
|
rjp::value case_9(void){
|
||||||
rjp::object obj;
|
rjp::object obj;
|
||||||
rjp::object sub = obj.add<rjp::object>("key"_ss);
|
rjp::object sub = obj.add<rjp::object>("key"_ss);
|
||||||
sub.add<rjp::boolean>("subkey"_ss, false);
|
sub.add<rjp::boolean>("subkey"_ss, false);
|
||||||
return std::move(obj);
|
return rjp::cast<rjp::value&&>(obj);
|
||||||
}
|
}
|
||||||
//handle object with multiple members
|
//handle object with multiple members
|
||||||
rjp::value case_10(void){
|
rjp::value case_10(void){
|
||||||
@ -50,7 +50,7 @@ rjp::value case_10(void){
|
|||||||
rjp::object sub = obj.add<rjp::object>("key"_ss);
|
rjp::object sub = obj.add<rjp::object>("key"_ss);
|
||||||
sub.add<rjp::boolean>("subkey"_ss, false);
|
sub.add<rjp::boolean>("subkey"_ss, false);
|
||||||
sub.add<rjp::boolean>("subkey2"_ss, true);
|
sub.add<rjp::boolean>("subkey2"_ss, true);
|
||||||
return std::move(obj);
|
return rjp::cast<rjp::value&&>(obj);
|
||||||
}
|
}
|
||||||
//handle object member ordering
|
//handle object member ordering
|
||||||
rjp::value case_11(void){
|
rjp::value case_11(void){
|
||||||
@ -58,7 +58,7 @@ rjp::value case_11(void){
|
|||||||
rjp::object sub = obj.add<rjp::object>("key"_ss);
|
rjp::object sub = obj.add<rjp::object>("key"_ss);
|
||||||
sub.add<rjp::boolean>("subkey2"_ss, true);
|
sub.add<rjp::boolean>("subkey2"_ss, true);
|
||||||
sub.add<rjp::boolean>("subkey"_ss, false);
|
sub.add<rjp::boolean>("subkey"_ss, false);
|
||||||
return std::move(obj);
|
return rjp::cast<rjp::value&&>(obj);
|
||||||
}
|
}
|
||||||
//handle orderedobject member ordering
|
//handle orderedobject member ordering
|
||||||
/*RJP_value* case_12(void){
|
/*RJP_value* case_12(void){
|
||||||
@ -82,13 +82,13 @@ RJP_value* case_13(void){
|
|||||||
rjp::value case_14(void){
|
rjp::value case_14(void){
|
||||||
rjp::array arr;
|
rjp::array arr;
|
||||||
arr.add<rjp::integer>(5);
|
arr.add<rjp::integer>(5);
|
||||||
return std::move(arr);
|
return rjp::cast<rjp::value&&>(arr);
|
||||||
}
|
}
|
||||||
//handle array with subarray
|
//handle array with subarray
|
||||||
rjp::value case_15(void){
|
rjp::value case_15(void){
|
||||||
rjp::array arr;
|
rjp::array arr;
|
||||||
arr.add<rjp::array>().add<rjp::boolean>(false);
|
arr.add<rjp::array>().add<rjp::boolean>(false);
|
||||||
return std::move(arr);
|
return rjp::cast<rjp::value&&>(arr);
|
||||||
}
|
}
|
||||||
//handle array with multiple elements
|
//handle array with multiple elements
|
||||||
rjp::value case_16(void){
|
rjp::value case_16(void){
|
||||||
@ -96,7 +96,7 @@ rjp::value case_16(void){
|
|||||||
rjp::array sub = arr.add<rjp::array>();
|
rjp::array sub = arr.add<rjp::array>();
|
||||||
sub.add<rjp::boolean>(false);
|
sub.add<rjp::boolean>(false);
|
||||||
sub.add<rjp::boolean>(true);
|
sub.add<rjp::boolean>(true);
|
||||||
return std::move(arr);
|
return rjp::cast<rjp::value&&>(arr);
|
||||||
}
|
}
|
||||||
//handle array with multiple elements and subarray
|
//handle array with multiple elements and subarray
|
||||||
rjp::value case_17(void){
|
rjp::value case_17(void){
|
||||||
@ -105,7 +105,7 @@ rjp::value case_17(void){
|
|||||||
rjp::array sub = arr.add<rjp::array>();
|
rjp::array sub = arr.add<rjp::array>();
|
||||||
sub.add<rjp::boolean>(false);
|
sub.add<rjp::boolean>(false);
|
||||||
sub.add<rjp::boolean>(true);
|
sub.add<rjp::boolean>(true);
|
||||||
return std::move(arr);
|
return rjp::cast<rjp::value&&>(arr);
|
||||||
}
|
}
|
||||||
//handle array with subobject with subarray
|
//handle array with subobject with subarray
|
||||||
rjp::value case_18(void){
|
rjp::value case_18(void){
|
||||||
@ -114,7 +114,7 @@ rjp::value case_18(void){
|
|||||||
rjp::object subobj = arr.add<rjp::object>();
|
rjp::object subobj = arr.add<rjp::object>();
|
||||||
rjp::array subarr = subobj.add<rjp::array>("key"_ss);
|
rjp::array subarr = subobj.add<rjp::array>("key"_ss);
|
||||||
subarr.add<rjp::boolean>(false);
|
subarr.add<rjp::boolean>(false);
|
||||||
return std::move(arr);
|
return rjp::cast<rjp::value&&>(arr);
|
||||||
}
|
}
|
||||||
//handle object with many members
|
//handle object with many members
|
||||||
rjp::value case_19(void){
|
rjp::value case_19(void){
|
||||||
@ -126,7 +126,7 @@ rjp::value case_19(void){
|
|||||||
subobj.add<rjp::boolean>(rexy::static_string(c), i % 2 == 0);
|
subobj.add<rjp::boolean>(rexy::static_string(c), i % 2 == 0);
|
||||||
c[3] += 1;
|
c[3] += 1;
|
||||||
}
|
}
|
||||||
return std::move(arr);
|
return rjp::cast<rjp::value&&>(arr);
|
||||||
}
|
}
|
||||||
//handle orderedobject with many members as array element
|
//handle orderedobject with many members as array element
|
||||||
/*RJP_value* case_20(void){
|
/*RJP_value* case_20(void){
|
||||||
@ -151,7 +151,7 @@ rjp::value case_21(void){
|
|||||||
rjp::array arr = obj.add<rjp::array>("arr"_ss);
|
rjp::array arr = obj.add<rjp::array>("arr"_ss);
|
||||||
for(int i = 0;i < 10;++i)
|
for(int i = 0;i < 10;++i)
|
||||||
arr.add<rjp::integer>(i);
|
arr.add<rjp::integer>(i);
|
||||||
return std::move(obj);
|
return rjp::cast<rjp::value&&>(obj);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
//handle unorderedobject conversion
|
//handle unorderedobject conversion
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user