diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index 16f95b0..83ff560 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -14,71 +14,13 @@ namespace chaiscript namespace detail { - template - struct Placeholder - { + struct Placeholder + { + static const std::tuple& placeholder() { + static const std::tuple d(std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,std::placeholders::_5,std::placeholders::_6,std::placeholders::_7,std::placeholders::_8,std::placeholders::_9,std::placeholders::_10); + return d; }; - - template<> - struct Placeholder<1> - { - static decltype(std::placeholders::_1) value() { return std::placeholders::_1; } - }; - - template<> - struct Placeholder<2> - { - static decltype(std::placeholders::_2) value() { return std::placeholders::_2; } - }; - - template<> - struct Placeholder<3> - { - static decltype(std::placeholders::_3) value() { return std::placeholders::_3; } - }; - - template<> - struct Placeholder<4> - { - static decltype(std::placeholders::_4) value() { return std::placeholders::_4; } - }; - - template<> - struct Placeholder<5> - { - static decltype(std::placeholders::_5) value() { return std::placeholders::_5; } - }; - - template<> - struct Placeholder<6> - { - static decltype(std::placeholders::_6) value() { return std::placeholders::_6; } - }; - - template<> - struct Placeholder<7> - { - static decltype(std::placeholders::_7) value() { return std::placeholders::_7; } - }; - - template<> - struct Placeholder<8> - { - static decltype(std::placeholders::_8) value() { return std::placeholders::_8; } - }; - - template<> - struct Placeholder<9> - { - static decltype(std::placeholders::_9) value() { return std::placeholders::_9; } - }; - - template<> - struct Placeholder<10> - { - static decltype(std::placeholders::_10) value() { return std::placeholders::_10; } - }; - + }; template struct Bind_First @@ -86,7 +28,7 @@ namespace chaiscript template static std::function bind(F f, InnerParams ... innerparams) { - return Bind_First::bind(f, innerparams..., Placeholder::value()); + return Bind_First::bind(f, innerparams..., std::get(Placeholder::placeholder())); } }; diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 32aa939..870d506 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -113,9 +113,7 @@ namespace chaiscript } - /** - * to_string function for internal use. Uses ostream operator<< - */ + /// to_string function for internal use. Uses ostream operator<< template std::string to_string(Input i) { @@ -124,10 +122,8 @@ namespace chaiscript return ss.str(); } - /** - * Internal function for converting from a string to a value - * uses ostream operator >> to perform the conversion - */ + /// Internal function for converting from a string to a value + /// uses ostream operator >> to perform the conversion template Input parse_string(const std::string &i) { @@ -136,12 +132,10 @@ namespace chaiscript ss >> t; return t; } - - - /** - * Add all common functions for a POD type. All operators, and - * common conversions - */ + + + /// Add all common functions for a POD type. All operators, and + /// common conversions template ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = ModulePtr(new Module())) { @@ -155,13 +149,11 @@ namespace chaiscript } - /** - * "clone" function for a shared_ptr type. This is used in the case - * where you do not want to make a deep copy of an object during cloning - * but want to instead maintain the shared_ptr. It is needed internally - * for handling of Proxy_Function object (that is, - * function variables. - */ + /// "clone" function for a shared_ptr type. This is used in the case + /// where you do not want to make a deep copy of an object during cloning + /// but want to instead maintain the shared_ptr. It is needed internally + /// for handling of Proxy_Function object (that is, + /// function variables. template std::shared_ptr shared_ptr_clone(const std::shared_ptr &p) { diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 222fd90..8ae7552 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -30,9 +30,7 @@ namespace chaiscript throw std::runtime_error("Attempted to dereference null Boxed_Value"); } - /** - * Generic Cast_Helper_Inner, for casting to any type - */ + /// Generic Cast_Helper_Inner, for casting to any type template struct Cast_Helper_Inner { @@ -54,50 +52,13 @@ namespace chaiscript { }; - /** - * Cast_Helper_Inner for casting to a const & type - */ + /// Cast_Helper_Inner for casting to a const & type template struct Cast_Helper_Inner : Cast_Helper_Inner { }; - /* /// Cast_Helper_Inner for casting to a const * type - template - struct Cast_Helper_Inner - { - typedef const Result * Result_Type; - - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) - { - if (ob.get_type_info().bare_equal_type_info(typeid(Result))) - { - return static_cast(ob.get_const_ptr()); - } else { - throw chaiscript::detail::exception::bad_any_cast(); - } - } - }; - - /// Cast_Helper_Inner for casting to a * type - template - struct Cast_Helper_Inner - { - typedef Result * Result_Type; - - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) - { - if (!ob.get_type_info().is_const() && ob.get_type_info().bare_equal_type_info(typeid(Result))) - { - return static_cast(ob.get_ptr()); - } else { - throw chaiscript::detail::exception::bad_any_cast(); - } - } - }; -*/ - template struct Cast_Helper_Inner { @@ -123,9 +84,7 @@ namespace chaiscript } }; - /** - * * Cast_Helper_Inner for casting to a * type - * */ + /// Cast_Helper_Inner for casting to a * type template struct Cast_Helper_Inner { @@ -142,9 +101,7 @@ namespace chaiscript }; - /** - * Cast_Helper_Inner for casting to a & type - */ + /// Cast_Helper_Inner for casting to a & type template struct Cast_Helper_Inner { @@ -161,9 +118,7 @@ namespace chaiscript } }; - /** - * Cast_Helper_Inner for casting to a std::shared_ptr<> type - */ + /// Cast_Helper_Inner for casting to a std::shared_ptr<> type template struct Cast_Helper_Inner > { @@ -175,9 +130,7 @@ namespace chaiscript } }; - /** - * Cast_Helper_Inner for casting to a std::shared_ptr type - */ + /// Cast_Helper_Inner for casting to a std::shared_ptr type template struct Cast_Helper_Inner > { @@ -194,9 +147,7 @@ namespace chaiscript } }; - /** - * Cast_Helper_Inner for casting to a const std::shared_ptr<> & type - */ + /// Cast_Helper_Inner for casting to a const std::shared_ptr<> & type template struct Cast_Helper_Inner > : Cast_Helper_Inner > { @@ -208,9 +159,7 @@ namespace chaiscript }; - /** - * Cast_Helper_Inner for casting to a const std::shared_ptr & type - */ + /// Cast_Helper_Inner for casting to a const std::shared_ptr & type template struct Cast_Helper_Inner > : Cast_Helper_Inner > { @@ -223,9 +172,7 @@ namespace chaiscript - /** - * Cast_Helper_Inner for casting to a Boxed_Value type - */ + /// Cast_Helper_Inner for casting to a Boxed_Value type template<> struct Cast_Helper_Inner { @@ -237,9 +184,7 @@ namespace chaiscript } }; - /** - * Cast_Helper_Inner for casting to a Boxed_Value & type - */ + /// Cast_Helper_Inner for casting to a Boxed_Value & type template<> struct Cast_Helper_Inner { @@ -252,9 +197,7 @@ namespace chaiscript }; - /** - * Cast_Helper_Inner for casting to a const Boxed_Value & type - */ + /// Cast_Helper_Inner for casting to a const Boxed_Value & type template<> struct Cast_Helper_Inner : Cast_Helper_Inner { @@ -266,9 +209,7 @@ namespace chaiscript }; - /** - * Cast_Helper_Inner for casting to a std::reference_wrapper type - */ + /// Cast_Helper_Inner for casting to a std::reference_wrapper type template struct Cast_Helper_Inner > : Cast_Helper_Inner { @@ -299,9 +240,7 @@ namespace chaiscript { }; - /** - * The exposed Cast_Helper object that by default just calls the Cast_Helper_Inner - */ + /// The exposed Cast_Helper object that by default just calls the Cast_Helper_Inner template struct Cast_Helper { diff --git a/include/chaiscript/dispatchkit/operators.hpp b/include/chaiscript/dispatchkit/operators.hpp index ed64b2c..4c2369f 100644 --- a/include/chaiscript/dispatchkit/operators.hpp +++ b/include/chaiscript/dispatchkit/operators.hpp @@ -8,6 +8,7 @@ #define CHAISCRIPT_OPERATORS_HPP_ #include "../chaiscript_defines.hpp" +#include "register_function.hpp" namespace chaiscript { @@ -15,442 +16,444 @@ namespace chaiscript { namespace operators { - template - Ret assign(L l, R r) - { - return (l = r); - } + namespace detail + { + template + auto assign(L l, R r) -> decltype((l = r)) + { + return (l = r); + } - template - Ret assign_bitwise_and(L l, R r) - { - return (l &= r); - } + template + auto assign_bitwise_and(L l, R r) -> decltype((l &r)) + { + return (l &= r); + } - template - Ret assign_xor(L l, R r) - { - return (l ^= r); - } + template + auto assign_xor(L l, R r) -> decltype((l^=r)) + { + return (l ^= r); + } - template - Ret assign_bitwise_or(L l, R r) - { - return (l |= r); - } + template + auto assign_bitwise_or(L l, R r) -> decltype((l |= r)) + { + return (l |= r); + } - template - Ret assign_difference(L l, R r) - { - return (l -= r); - } + template + auto assign_difference(L l, R r) -> decltype(( l -= r)) + { + return (l -= r); + } - template - Ret assign_left_shift(L l, R r) - { - return (l <<= r); - } + template + auto assign_left_shift(L l, R r) -> decltype(( l <<= r)) + { + return (l <<= r); + } - template - Ret assign_product(L l, R r) - { - return (l *= r); - } + template + auto assign_product(L l, R r) -> decltype(( l *= r )) + { + return (l *= r); + } - template - Ret assign_quotient(L l, R r) - { - return (l /= r); - } + template + auto assign_quotient(L l, R r) -> decltype(( l /= r )) + { + return (l /= r); + } - template - Ret assign_remainder(L l, R r) - { - return (l %= r); - } + template + auto assign_remainder(L l, R r) -> decltype(( l %= r )) + { + return (l %= r); + } - template - Ret assign_right_shift(L l, R r) - { - return (l >>= r); - } + template + auto assign_right_shift(L l, R r) -> decltype(( l >>= r)) + { + return (l >>= r); + } - template - Ret assign_sum(L l, R r) - { - return (l += r); - } + template + auto assign_sum(L l, R r) -> decltype(( l += r)) + { + return (l += r); + } - template - Ret prefix_decrement(L l) - { - return (--l); - } + template + auto prefix_decrement(L l) -> decltype(( --l )) + { + return (--l); + } - template - Ret prefix_increment(L l) - { - return (++l); - } + template + auto prefix_increment(L l) -> decltype(( ++l )) + { + return (++l); + } - template - Ret equal(L l, R r) - { - return (l == r); - } + template + auto equal(L l, R r) -> decltype(( l == r )) + { + return (l == r); + } - template - Ret greater_than(L l, R r) - { - return (l > r); - } + template + auto greater_than(L l, R r) -> decltype(( l > r )) + { + return (l > r); + } - template - Ret greater_than_equal(L l, R r) - { - return (l >= r); - } + template + auto greater_than_equal(L l, R r) -> decltype(( l >= r )) + { + return (l >= r); + } - template - Ret less_than(L l, R r) - { - return (l < r); - } + template + auto less_than(L l, R r) -> decltype(( l < r )) + { + return (l < r); + } - template - Ret less_than_equal(L l, R r) - { - return (l <= r); - } + template + auto less_than_equal(L l, R r) -> decltype(( l <= r )) + { + return (l <= r); + } - template - Ret logical_compliment(L l) - { - return (!l); - } + template + auto logical_compliment(L l) -> decltype(( !l )) + { + return (!l); + } - template - Ret not_equal(L l, R r) - { - return (l != r); - } + template + auto not_equal(L l, R r) -> decltype(( l != r )) + { + return (l != r); + } - template - Ret addition(L l, R r) - { - return (l + r); - } + template + auto addition(L l, R r) -> decltype(( l + r )) + { + return (l + r); + } - template - Ret unary_plus(L l) - { - return (+l); - } + template + auto unary_plus(L l) -> decltype(( +l )) + { + return (+l); + } - template - Ret subtraction(L l, R r) - { - return (l - r); - } + template + auto subtraction(L l, R r) -> decltype(( l - r )) + { + return (l - r); + } - template - Ret unary_minus(L l) - { + template + auto unary_minus(L l) -> decltype(( -l )) + { #ifdef CHAISCRIPT_MSVC #pragma warning(push) #pragma warning(disable : 4146) - return (-l); + return (-l); #pragma warning(pop) #else - return (-l); + return (-l); #endif - } + } - template - Ret bitwise_and(L l, R r) - { - return (l & r); - } + template + auto bitwise_and(L l, R r) -> decltype(( l & r )) + { + return (l & r); + } - template - Ret bitwise_compliment(L l) - { - return (~l); - } + template + auto bitwise_compliment(L l) -> decltype(( ~l )) + { + return (~l); + } - template - Ret bitwise_xor(L l, R r) - { - return (l ^ r); - } + template + auto bitwise_xor(L l, R r) -> decltype(( l ^ r )) + { + return (l ^ r); + } - template - Ret bitwise_or(L l, R r) - { - return (l | r); - } + template + auto bitwise_or(L l, R r) -> decltype(( l | r )) + { + return (l | r); + } - template - Ret division(L l, R r) - { - return (l / r); - } + template + auto division(L l, R r) -> decltype(( l / r )) + { + return (l / r); + } - template - Ret left_shift(L l, R r) - { - return l << r; - } + template + auto left_shift(L l, R r) -> decltype(( l << r )) + { + return l << r; + } - template - Ret multiplication(L l, R r) - { - return l * r; - } + template + auto multiplication(L l, R r) -> decltype(( l * r )) + { + return l * r; + } - template - Ret remainder(L l, R r) - { - return (l % r); - } - - template - Ret right_shift(L l, R r) - { - return (l >> r); - } + template + auto remainder(L l, R r) -> decltype(( l % r )) + { + return (l % r); + } + template + auto right_shift(L l, R r) -> decltype(( l >> r )) + { + return (l >> r); + } + } template ModulePtr assign(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign), "="); + m->add(chaiscript::fun(&detail::assign), "="); return m; } template ModulePtr assign_bitwise_and(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_bitwise_and), "&="); + m->add(chaiscript::fun(&detail::assign_bitwise_and), "&="); return m; } template ModulePtr assign_xor(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_xor), "^="); + m->add(chaiscript::fun(&detail::assign_xor), "^="); return m; } template ModulePtr assign_bitwise_or(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_bitwise_or), "|="); + m->add(chaiscript::fun(&detail::assign_bitwise_or), "|="); return m; } template ModulePtr assign_difference(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_difference), "-="); + m->add(chaiscript::fun(&detail::assign_difference), "-="); return m; } template ModulePtr assign_left_shift(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_left_shift), "<<="); + m->add(chaiscript::fun(&detail::assign_left_shift), "<<="); return m; } template ModulePtr assign_product(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_product), "*="); + m->add(chaiscript::fun(&detail::assign_product), "*="); return m; } template ModulePtr assign_quotient(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_quotient), "/="); + m->add(chaiscript::fun(&detail::assign_quotient), "/="); return m; } template ModulePtr assign_remainder(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_remainder), "%="); + m->add(chaiscript::fun(&detail::assign_remainder), "%="); return m; } template ModulePtr assign_right_shift(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_right_shift), ">>="); + m->add(chaiscript::fun(&detail::assign_right_shift), ">>="); return m; } template ModulePtr assign_sum(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&assign_sum), "+="); + m->add(chaiscript::fun(&detail::assign_sum), "+="); return m; } template ModulePtr prefix_decrement(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&prefix_decrement), "--"); + m->add(chaiscript::fun(&detail::prefix_decrement), "--"); return m; } template ModulePtr prefix_increment(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&prefix_increment), "++"); + m->add(chaiscript::fun(&detail::prefix_increment), "++"); return m; } template ModulePtr equal(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&equal), "=="); + m->add(chaiscript::fun(&detail::equal), "=="); return m; } template ModulePtr greater_than(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&greater_than), ">"); + m->add(chaiscript::fun(&detail::greater_than), ">"); return m; } template ModulePtr greater_than_equal(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&greater_than_equal), ">="); + m->add(chaiscript::fun(&detail::greater_than_equal), ">="); return m; } template ModulePtr less_than(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&less_than), "<"); + m->add(chaiscript::fun(&detail::less_than), "<"); return m; } template ModulePtr less_than_equal(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&less_than_equal), "<="); + m->add(chaiscript::fun(&detail::less_than_equal), "<="); return m; } template ModulePtr logical_compliment(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&logical_compliment), "!"); + m->add(chaiscript::fun(&detail::logical_compliment), "!"); return m; } template ModulePtr not_equal(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(¬_equal), "!="); + m->add(chaiscript::fun(&detail::not_equal), "!="); return m; } template ModulePtr addition(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&addition), "+"); + m->add(chaiscript::fun(&detail::addition), "+"); return m; } template ModulePtr unary_plus(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&unary_plus), "+"); + m->add(chaiscript::fun(&detail::unary_plus), "+"); return m; } template ModulePtr subtraction(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&subtraction), "-"); + m->add(chaiscript::fun(&detail::subtraction), "-"); return m; } template ModulePtr unary_minus(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&unary_minus), "-"); + m->add(chaiscript::fun(&detail::unary_minus), "-"); return m; } template ModulePtr bitwise_and(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&bitwise_and), "&"); + m->add(chaiscript::fun(&detail::bitwise_and), "&"); return m; } template ModulePtr bitwise_compliment(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&bitwise_compliment), "~"); + m->add(chaiscript::fun(&detail::bitwise_compliment), "~"); return m; } template ModulePtr bitwise_xor(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&bitwise_xor), "^"); + m->add(chaiscript::fun(&detail::bitwise_xor), "^"); return m; } template ModulePtr bitwise_or(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&bitwise_or), "|"); + m->add(chaiscript::fun(&detail::bitwise_or), "|"); return m; } template ModulePtr division(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&division), "/"); + m->add(chaiscript::fun(&detail::division), "/"); return m; } template ModulePtr left_shift(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&left_shift), "<<"); + m->add(chaiscript::fun(&detail::left_shift), "<<"); return m; } template ModulePtr multiplication(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&multiplication), "*"); + m->add(chaiscript::fun(&detail::multiplication), "*"); return m; } template ModulePtr remainder(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&remainder), "%"); + m->add(chaiscript::fun(&detail::remainder), "%"); return m; } template ModulePtr right_shift(ModulePtr m = ModulePtr(new Module())) { - m->add(fun(&right_shift), ">>"); + m->add(chaiscript::fun(&detail::right_shift), ">>"); return m; } }