mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-04-30 19:09:26 +08:00
Various C++17 considerations
This commit is contained in:
parent
ac78e978fe
commit
4213f24761
@ -17,6 +17,7 @@
|
||||
#ifndef CHAISCRIPT_NO_THREADS
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#else
|
||||
#ifndef CHAISCRIPT_NO_THREADS_WARNING
|
||||
#pragma message ("ChaiScript is compiling without thread safety.")
|
||||
@ -49,13 +50,13 @@ namespace chaiscript
|
||||
using unique_lock = std::unique_lock<T>;
|
||||
|
||||
template<typename T>
|
||||
using shared_lock = std::unique_lock<T>;
|
||||
using shared_lock = std::shared_lock<T>;
|
||||
|
||||
template<typename T>
|
||||
using lock_guard = std::lock_guard<T>;
|
||||
|
||||
|
||||
using shared_mutex = std::mutex;
|
||||
using std::shared_mutex;
|
||||
|
||||
using std::mutex;
|
||||
|
||||
|
||||
@ -86,21 +86,15 @@ namespace chaiscript {
|
||||
Any(Any &&) = default;
|
||||
Any &operator=(Any &&t_any) = default;
|
||||
|
||||
Any(const Any &t_any)
|
||||
{
|
||||
if (!t_any.empty())
|
||||
{
|
||||
m_data = t_any.m_data->clone();
|
||||
} else {
|
||||
m_data.reset();
|
||||
}
|
||||
Any(const Any &t_any)
|
||||
: m_data(t_any.empty() ? nullptr : t_any.m_data->clone())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<typename ValueType,
|
||||
typename = typename std::enable_if<!std::is_same<Any, typename std::decay<ValueType>::type>::value>::type>
|
||||
typename = std::enable_if_t<!std::is_same_v<Any, std::decay_t<ValueType>>>>
|
||||
explicit Any(ValueType &&t_value)
|
||||
: m_data(std::unique_ptr<Data>(new Data_Impl<typename std::decay<ValueType>::type>(std::forward<ValueType>(t_value))))
|
||||
: m_data(std::unique_ptr<Data>(new Data_Impl<std::decay_t<ValueType>>(std::forward<ValueType>(t_value))))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@ -1049,7 +1049,7 @@ namespace chaiscript
|
||||
if (!functions.empty()) {
|
||||
try {
|
||||
if (is_no_param) {
|
||||
std::vector<Boxed_Value> tmp_params(params);
|
||||
auto tmp_params(params);
|
||||
tmp_params.insert(tmp_params.begin() + 1, var(t_name));
|
||||
return do_attribute_call(2, tmp_params, functions, t_conversions);
|
||||
} else {
|
||||
@ -1080,10 +1080,9 @@ namespace chaiscript
|
||||
const Type_Conversions_State &t_conversions) const
|
||||
{
|
||||
uint_fast32_t loc = t_loc;
|
||||
const auto funs = get_function(t_name, loc);
|
||||
if (funs.first != loc) { t_loc = uint_fast32_t(funs.first);
|
||||
}
|
||||
return dispatch::dispatch(*funs.second, params, t_conversions);
|
||||
const auto [func_loc, func] = get_function(t_name, loc);
|
||||
if (func_loc != loc) { t_loc = uint_fast32_t(func_loc); }
|
||||
return dispatch::dispatch(*func, params, t_conversions);
|
||||
}
|
||||
|
||||
|
||||
@ -1102,12 +1101,12 @@ namespace chaiscript
|
||||
/// Dump function to stdout
|
||||
void dump_function(const std::pair<const std::string, Proxy_Function > &f) const
|
||||
{
|
||||
std::vector<Type_Info> params = f.second->get_param_types();
|
||||
const auto params = f.second->get_param_types();
|
||||
|
||||
dump_type(params.front());
|
||||
std::cout << " " << f.first << "(";
|
||||
|
||||
for (std::vector<Type_Info>::const_iterator itr = params.begin() + 1;
|
||||
for (auto itr = params.begin() + 1;
|
||||
itr != params.end();
|
||||
)
|
||||
{
|
||||
@ -1132,7 +1131,7 @@ namespace chaiscript
|
||||
throw chaiscript::exception::arity_error(static_cast<int>(params.size()), 1);
|
||||
}
|
||||
|
||||
const Const_Proxy_Function &f = this->boxed_cast<Const_Proxy_Function>(params[0]);
|
||||
const auto &f = this->boxed_cast<Const_Proxy_Function>(params[0]);
|
||||
const Type_Conversions_State convs(m_conversions, m_conversions.conversion_saves());
|
||||
|
||||
return const_var(f->call_match(std::vector<Boxed_Value>(params.begin() + 1, params.end()), convs));
|
||||
@ -1142,25 +1141,17 @@ namespace chaiscript
|
||||
void dump_system() const
|
||||
{
|
||||
std::cout << "Registered Types: \n";
|
||||
std::vector<std::pair<std::string, Type_Info> > types = get_types();
|
||||
for (std::vector<std::pair<std::string, Type_Info> >::const_iterator itr = types.begin();
|
||||
itr != types.end();
|
||||
++itr)
|
||||
for (const auto &[type_name, type] : get_types() )
|
||||
{
|
||||
std::cout << itr->first << ": ";
|
||||
std::cout << itr->second.bare_name();
|
||||
std::cout << '\n';
|
||||
std::cout << type_name << ": " << type.bare_name() << '\n';
|
||||
}
|
||||
|
||||
std::cout << '\n';
|
||||
std::vector<std::pair<std::string, Proxy_Function > > funcs = get_functions();
|
||||
|
||||
std::cout << "Functions: \n";
|
||||
for (std::vector<std::pair<std::string, Proxy_Function > >::const_iterator itr = funcs.begin();
|
||||
itr != funcs.end();
|
||||
++itr)
|
||||
for (const auto &func : get_functions())
|
||||
{
|
||||
dump_function(*itr);
|
||||
dump_function(func);
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace chaiscript
|
||||
{
|
||||
void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override
|
||||
{
|
||||
(void)std::initializer_list<int>{(throw_type<T>(bv, t_engine), 0)...};
|
||||
(throw_type<T>(bv, t_engine), ...);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -92,9 +92,9 @@ namespace chaiscript
|
||||
template<typename Callable, typename Ret, typename ... Params, size_t ... I>
|
||||
Ret call_func(Ret (*)(Params...),
|
||||
std::index_sequence<I...>, const Callable &f,
|
||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions)
|
||||
[[maybe_unused]] const std::vector<Boxed_Value> ¶ms,
|
||||
[[maybe_unused]] const Type_Conversions_State &t_conversions)
|
||||
{
|
||||
(void)params; (void)t_conversions;
|
||||
return f(boxed_cast<Params>(params[I], &t_conversions)...);
|
||||
}
|
||||
|
||||
|
||||
@ -557,7 +557,6 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
||||
std::string load_module(const std::string &t_module_name)
|
||||
{
|
||||
#ifdef CHAISCRIPT_NO_DYNLOAD
|
||||
(void)t_module_name; // -Wunused-parameter
|
||||
throw chaiscript::exception::load_module_error("Loadable module support was disabled (CHAISCRIPT_NO_DYNLOAD)");
|
||||
#else
|
||||
std::vector<exception::load_module_error> errors;
|
||||
|
||||
@ -24,7 +24,7 @@ namespace chaiscript {
|
||||
|
||||
template<typename Tracer>
|
||||
auto optimize(eval::AST_Node_Impl_Ptr<Tracer> p) {
|
||||
(void)std::initializer_list<int>{ (p = static_cast<T&>(*this).optimize(std::move(p)), 0)... };
|
||||
( (p = static_cast<T&>(*this).optimize(std::move(p))), ... );
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
@ -29,7 +29,7 @@ namespace chaiscript {
|
||||
}
|
||||
|
||||
void do_trace(const chaiscript::detail::Dispatch_State &ds, const AST_Node_Impl<Tracer<T...>> *node) {
|
||||
(void)std::initializer_list<int>{ (static_cast<T&>(*this).trace(ds, node), 0)... };
|
||||
(static_cast<T&>(*this).trace(ds, node), ... );
|
||||
}
|
||||
|
||||
static void trace(const chaiscript::detail::Dispatch_State &ds, const AST_Node_Impl<Tracer<T...>> *node) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user