8000 Add overloads for cosnt *& casts · ChaiScript/ChaiScript@4826bdd · GitHub
[go: up one dir, main page]

Skip to content

Commit 4826bdd

Browse files
committed
Add overloads for cosnt *& casts
1 parent 6fe7f5c commit 4826bdd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

include/chaiscript/dispatchkit/boxed_cast_helper.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace chaiscript
6262
{
6363
if (ob.get_type_info().bare_equal_type_info(typeid(Result)))
6464
{
65-
return static_cast<const Result *>(throw_if_null(ob.get_const_ptr()));
65+
return static_cast<const Result *>(ob.get_const_ptr());
6666
} else {
6767
throw chaiscript::detail::exception::bad_any_cast();
6868
}
@@ -76,15 +76,26 @@ namespace chaiscript
7676
typedef Result * Result_Type;
7777
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
7878
{
79-
if (!ob.get_type_info().is_const() && ob.get_type_info() == typeid(Result))
79+
if (!ob.get_type_info().is_const() && ob.get_type_info().bare_equal_type_info(typeid(Result)))
8080
{
81-
return static_cast<Result *>(throw_if_null(ob.get_ptr()));
81+
return static_cast<Result *>(ob.get_ptr());
8282
} else {
8383
throw chaiscript::detail::exception::bad_any_cast();
8484
}
8585
}
8686
};
8787

88+
template<typename Result>
89+
struct Cast_Helper_Inner<Result * const &> : public Cast_Helper_Inner<Result *>
90+
{
91+
};
92+
93+
template<typename Result>
94+
struct Cast_Helper_Inner<const Result * const &> : public Cast_Helper_Inner<const Result *>
95+
{
96+
};
97+
98+
8899
/// Cast_Helper_Inner for casting to a & type
89100
template<typename Result>
90101
struct Cast_Helper_Inner<const Result &>

unittests/boxed_cast_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass)
1313
try {
1414
To ret = chaiscript::boxed_cast<To>(bv);
1515
use(ret);
16-
} catch (const chaiscript::exception::bad_boxed_cast &/*e*/) {
16+
} catch (const chaiscript::exception::bad_boxed_cast &e) {
1717
if (expectedpass) {
18-
// std::cerr << "Failure in run_test_type_conversion: " << e.what() << '\n';
18+
std::cerr << "Failure in run_test_type_conversion: " << e.what() << '\n';
1919
return false;
2020
} else {
2121
return true;

0 commit comments

Comments
 (0)
0