mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-01-01 03:12:23 +08:00
Merge branch 'release-6.x' into develop
This commit is contained in:
commit
5db87a9175
@ -167,17 +167,33 @@ namespace chaiscript
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename Ret>
|
||||
struct Handle_Return<const Ret &>
|
||||
template<typename Ret, bool Ptr>
|
||||
struct Handle_Return_Ref
|
||||
{
|
||||
static Boxed_Value handle(const Ret &r)
|
||||
template<typename T>
|
||||
static Boxed_Value handle(T &&r)
|
||||
{
|
||||
return Boxed_Value(std::cref(r), true);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Ret>
|
||||
struct Handle_Return_Ref<Ret, true>
|
||||
{
|
||||
template<typename T>
|
||||
static Boxed_Value handle(T &&r)
|
||||
{
|
||||
return Boxed_Value(typename std::remove_reference<decltype(r)>::type{r}, true);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Ret>
|
||||
struct Handle_Return<const Ret &> : Handle_Return_Ref<const Ret &, std::is_pointer<typename std::remove_reference<const Ret &>::type>::value>
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename Ret>
|
||||
struct Handle_Return<const Ret>
|
||||
{
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
Notes:
|
||||
=======
|
||||
Current Version: 6.1.0
|
||||
Current Version: 6.1.1
|
||||
|
||||
### Changes since 6.1.0
|
||||
|
||||
* Handle the returning of `&` to `*` types. This specifically comes up with `std::vector<int *>` and similar containers
|
||||
|
||||
### Changes since 6.0.0
|
||||
|
||||
|
||||
@ -204,6 +204,41 @@ TEST_CASE("Throw int or double")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Deduction of pointer return types")
|
||||
{
|
||||
int val = 5;
|
||||
int *val_ptr = &val;
|
||||
auto &val_ptr_ref = val_ptr;
|
||||
const auto &val_ptr_const_ref = val_ptr;
|
||||
|
||||
auto get_val_ptr = [&]() -> int * { return val_ptr; };
|
||||
auto get_val_const_ptr = [&]() -> int const * { return val_ptr; };
|
||||
auto get_val_ptr_ref = [&]() -> int *& { return val_ptr_ref; };
|
||||
auto get_val_ptr_const_ref = [&]() -> int * const & { return val_ptr_const_ref; };
|
||||
// auto get_val_const_ptr_const_ref = [ref=std::cref(val_ptr)]() -> int const * const & { return ref.get(); };
|
||||
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(), create_chaiscript_parser());
|
||||
chai.add(chaiscript::fun(get_val_ptr), "get_val_ptr");
|
||||
chai.add(chaiscript::fun(get_val_const_ptr), "get_val_const_ptr");
|
||||
chai.add(chaiscript::fun(get_val_ptr_ref), "get_val_ptr_ref");
|
||||
chai.add(chaiscript::fun(get_val_ptr_const_ref), "get_val_ptr_const_ref");
|
||||
// chai.add(chaiscript::fun(get_val_const_ptr_const_ref), "get_val_const_ptr_const_ref");
|
||||
|
||||
CHECK(chai.eval<int *>("get_val_ptr()") == &val);
|
||||
CHECK(*chai.eval<int *>("get_val_ptr()") == val);
|
||||
CHECK(chai.eval<int const *>("get_val_const_ptr()") == &val);
|
||||
CHECK(*chai.eval<int const *>("get_val_const_ptr()") == val);
|
||||
|
||||
// note that we cannot maintain the references here,
|
||||
// chaiscript internals cannot handle that, effectively pointer to pointer
|
||||
CHECK(chai.eval<int *>("get_val_ptr_ref()") == &val);
|
||||
CHECK(*chai.eval<int *>("get_val_ptr_ref()") == val);
|
||||
CHECK(chai.eval<int *>("get_val_ptr_const_ref()") == &val);
|
||||
CHECK(*chai.eval<int *>("get_val_ptr_const_ref()") == val);
|
||||
// CHECK(chai.eval<int const *>("get_val_const_ptr_const_ref()") == &val);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Throw a runtime_error")
|
||||
{
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(),create_chaiscript_parser());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user