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