diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c046f0..3d0e6eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,10 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") # enable correct __cplusplus macro +endif() + option(BUILD_SHARED_LIBS "Build shared library" ON) option(BUILD_TESTING "Build and run tests" OFF) option(BUILD_DOCUMENTATION "Build documentation" OFF) diff --git a/test/test.hpp b/test/test.hpp index db62f9e..b3c99fa 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -31,13 +31,13 @@ std::ostream& operator<<(std::ostream& os, std::array const& array) return print_sequence(os, array, "[]"); } -template::value>::type> +template std::ostream& operator<<(std::ostream& os, std::basic_string const& string) { return print_sequence(os, string, "''"); } -template>> +template std::ostream& operator<<(std::ostream& os, std::basic_string_view const& string_view) { return print_sequence(os, string_view, "''"); @@ -53,6 +53,16 @@ inline std::ostream& operator<<(std::ostream& os, char16_t const* str) return print_sequence(os, std::basic_string_view(str), "''"); } +inline std::ostream& operator<<(std::ostream& os, char32_t ch) +{ + return os << static_cast(ch); +} + +inline std::ostream& operator<<(std::ostream& os, char32_t const* str) +{ + return print_sequence(os, std::basic_string_view(str), "''"); +} + inline std::ostream& operator<<(std::ostream& os, wchar_t ch) { return os << static_cast(ch); @@ -141,10 +151,10 @@ std::ostream& operator<<(std::ostream& os, std::pair const& pair) return os << pair.first << ": " << pair.second; } -template::value>::type> +template requires std::is_enum_v std::ostream& operator<<(std::ostream& os, Enum value) { - return os << static_cast::type>(value); + return os << static_cast>(value); } template diff --git a/test/test_call_from_v8.cpp b/test/test_call_from_v8.cpp index 369340e..4c5f9c7 100644 --- a/test/test_call_from_v8.cpp +++ b/test/test_call_from_v8.cpp @@ -39,47 +39,47 @@ using arg_convert = typename call_from_v8_traits::template arg_converter< typename call_from_v8_traits::template arg_type, Traits>; // fundamental type converters -static_assert(std::is_same, v8pp::convert>::value, "y(int)"); -static_assert(std::is_same, v8pp::convert>::value, "y(int)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); -static_assert(std::is_same, v8pp::convert>::value, "y(int)"); -static_assert(std::is_same, v8pp::convert>::value, "y(int)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); // cv arg converters static void s(std::string, std::vector&, std::shared_ptr const&, std::string*, std::string const*) {} -static_assert(std::is_same, v8pp::convert>::value, "s(string)"); -static_assert(std::is_same, v8pp::convert>::value, "s(string)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); -static_assert(std::is_same, v8pp::convert>>::value, "s(vector&)"); -static_assert(std::is_same, v8pp::convert>>::value, "s(vector&)"); +static_assert(std::same_as, v8pp::convert>>); +static_assert(std::same_as, v8pp::convert>>); -static_assert(std::is_same, v8pp::convert>>::value, "s(std::shared_ptr const&)"); -static_assert(std::is_same, v8pp::convert>>::value, "s(std::shared_ptr const&)"); +static_assert(std::same_as, v8pp::convert>>); +static_assert(std::same_as, v8pp::convert>>); -static_assert(std::is_same, v8pp::convert>::value, "s(std::string*)"); -static_assert(std::is_same, v8pp::convert>::value, "s(std::string*)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); -static_assert(std::is_same, v8pp::convert>::value, "s(std::string const*)"); -static_assert(std::is_same, v8pp::convert>::value, "s(std::string const*)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); // fundamental types cv arg converters static void t(int, char&, bool const&, float*, char const*) {} -static_assert(std::is_same, v8pp::convert>::value, "t(int)"); -static_assert(std::is_same, v8pp::convert>::value, "t(int)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); -static_assert(std::is_same, v8pp::convert>::value, "t(char&)"); -static_assert(std::is_same, v8pp::convert>::value, "t(char&)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); -static_assert(std::is_same, v8pp::convert>::value, "t(bool const&)"); -static_assert(std::is_same, v8pp::convert>::value, "t(bool const&)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); -static_assert(std::is_same, v8pp::convert>::value, "t(float*)"); -static_assert(std::is_same, v8pp::convert>::value, "t(float*)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); -static_assert(std::is_same, v8pp::convert>::value, "t(char const*)"); -static_assert(std::is_same, v8pp::convert>::value, "t(char const*)"); +static_assert(std::same_as, v8pp::convert>); +static_assert(std::same_as, v8pp::convert>); void test_call_from_v8() { diff --git a/test/test_class.cpp b/test/test_class.cpp index fb39a8a..3cc19ac 100644 --- a/test/test_class.cpp +++ b/test/test_class.cpp @@ -190,10 +190,10 @@ void test_class_() .static_("my_static_const_var", 42, true) ; - static_assert(std::is_move_constructible::value, ""); - static_assert(!std::is_move_assignable::value, ""); - static_assert(!std::is_copy_assignable::value, ""); - static_assert(!std::is_copy_constructible::value, ""); + static_assert(std::is_move_constructible_v); + static_assert(!std::is_move_assignable_v); + static_assert(!std::is_copy_assignable_v); + static_assert(!std::is_copy_constructible_v); v8pp::class_ Y_class(isolate); Y_class @@ -324,7 +324,7 @@ void test_class_() context.isolate()->RequestGarbageCollectionForTesting( v8::Isolate::GarbageCollectionType::kFullGarbageCollection); - bool const use_shared_ptr = std::is_same::value; + bool constexpr use_shared_ptr = std::same_as; check_eq("Y count after GC", Y::instance_count, 1 + 2 * use_shared_ptr); // y1 + (y2 + y3 when use_shared_ptr) diff --git a/test/test_context.cpp b/test/test_context.cpp index 37017f6..62ff721 100644 --- a/test/test_context.cpp +++ b/test/test_context.cpp @@ -6,10 +6,10 @@ #include -static_assert(std::is_move_constructible::value, ""); -static_assert(std::is_move_assignable::value, ""); -static_assert(!std::is_copy_assignable::value, ""); -static_assert(!std::is_copy_constructible::value, ""); +static_assert(std::is_move_constructible_v); +static_assert(std::is_move_assignable_v); +static_assert(!std::is_copy_assignable_v); +static_assert(!std::is_copy_constructible_v); void test_context() { diff --git a/test/test_convert.cpp b/test/test_convert.cpp index 7a584b6..ca0b80e 100644 --- a/test/test_convert.cpp +++ b/test/test_convert.cpp @@ -220,12 +220,12 @@ void check_range(v8::Isolate* isolate) T zero{ 0 }; T min, max; - if constexpr (std::is_same_v) + if constexpr (std::same_as) { min = V8_MIN_INT; max = V8_MAX_INT; } - else if constexpr (std::is_same_v) + else if constexpr (std::same_as) { min = 0; max = V8_MAX_INT; diff --git a/test/test_module.cpp b/test/test_module.cpp index 0e20697..5556adb 100644 --- a/test/test_module.cpp +++ b/test/test_module.cpp @@ -14,10 +14,10 @@ static int x = 1; static int get_x() { return x + 1; } static void set_x(int v) { x = v - 1; } -static_assert(std::is_move_constructible::value, ""); -static_assert(std::is_move_assignable::value, ""); -static_assert(!std::is_copy_assignable::value, ""); -static_assert(!std::is_copy_constructible::value, ""); +static_assert(std::is_move_constructible_v); +static_assert(std::is_move_assignable_v); +static_assert(!std::is_copy_assignable_v); +static_assert(!std::is_copy_constructible_v); void test_module() { diff --git a/test/test_ptr_traits.cpp b/test/test_ptr_traits.cpp index e78688d..74b6b3c 100644 --- a/test/test_ptr_traits.cpp +++ b/test/test_ptr_traits.cpp @@ -120,15 +120,15 @@ void test_raw_ptr_traits() X x; traits::pointer_type ptr = &x; - static_assert(std::is_same::value, "raw pointer_type"); - static_assert(std::is_same::value, "raw const_pointer_type"); + static_assert(std::same_as); + static_assert(std::same_as); - static_assert(std::is_same, X*>::value, "raw object_pointer_type"); - static_assert(std::is_same, X const*>::value, "raw object_const_pointer_type"); + static_assert(std::same_as, X*>); + static_assert(std::same_as, X const*>); - static_assert(std::is_same::value, "raw object_id"); - static_assert(std::is_same, v8pp::convert>::value, "raw convert_ptr"); - static_assert(std::is_same, v8pp::convert>::value, "raw convert_ref"); + static_assert(std::same_as); + static_assert(std::same_as, v8pp::convert>); + static_assert(std::same_as, v8pp::convert>); traits::object_id id = traits::pointer_id(ptr); check_eq("raw_ptr_traits::pointer_id", id, &x); @@ -145,15 +145,15 @@ void test_shared_ptr_traits() std::shared_ptr y(Y::make(1), Y::done); traits::pointer_type ptr = y; - static_assert(std::is_same>::value, "shared pointer_type"); - static_assert(std::is_same>::value, "shared const_pointer_type"); + static_assert(std::same_as>); + static_assert(std::same_as>); - static_assert(std::is_same, std::shared_ptr>::value, "shared object_pointer_type"); - static_assert(std::is_same, std::shared_ptr>::value, "shared object_const_pointer_type"); + static_assert(std::same_as, std::shared_ptr>); + static_assert(std::same_as, std::shared_ptr>); - static_assert(std::is_same::value, "shared object_id"); - static_assert(std::is_same, v8pp::convert>>::value, "shared convert_ptr"); - static_assert(std::is_same, v8pp::convert>::value, "shared convert_ref"); + static_assert(std::same_as); + static_assert(std::same_as, v8pp::convert>>); + static_assert(std::same_as, v8pp::convert>); traits::object_id id = traits::pointer_id(ptr); check_eq("shared_ptr_traits::pointer_id", id, y.get()); diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 2672163..b409cce 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -10,14 +10,14 @@ template void test_ret(F&&) { using R = typename v8pp::detail::function_traits::return_type; - static_assert(std::is_same::value, "wrong return_type"); + static_assert(std::same_as); } template void test_args(F&&) { using Args = typename v8pp::detail::function_traits::arguments; - static_assert(std::is_same::value, "wrong arguments"); + static_assert(std::same_as); } template @@ -134,9 +134,9 @@ void test_tuple_tail() { using v8pp::detail::tuple_tail; - static_assert(std::is_same>::type, std::tuple<>>::value, ""); - static_assert(std::is_same>::type, std::tuple>::value, ""); - static_assert(std::is_same>::type, std::tuple>::value, ""); + static_assert(std::same_as>::type, std::tuple<>>); + static_assert(std::same_as>::type, std::tuple>); + static_assert(std::same_as>::type, std::tuple>); } int f() { return 1; } diff --git a/v8pp/call_from_v8.hpp b/v8pp/call_from_v8.hpp index 013cc6a..771bbc9 100644 --- a/v8pp/call_from_v8.hpp +++ b/v8pp/call_from_v8.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_CALL_FROM_V8_HPP_INCLUDED -#define V8PP_CALL_FROM_V8_HPP_INCLUDED +#pragma once #include #include @@ -9,17 +8,16 @@ #include "v8pp/convert.hpp" #include "v8pp/utility.hpp" -namespace v8pp { namespace detail { +namespace v8pp::detail { template struct call_from_v8_traits { static constexpr size_t offset = Offset; - static constexpr bool is_mem_fun = std::is_member_function_pointer::value; + static constexpr bool is_mem_fun = std::is_member_function_pointer_v; using arguments = typename function_traits::arguments; - static constexpr size_t arg_count = - std::tuple_size::value - is_mem_fun - offset; + static constexpr size_t arg_count = std::tuple_size_v - is_mem_fun - offset; template struct tuple_element @@ -56,11 +54,11 @@ struct call_from_v8_traits template> inline constexpr bool is_direct_args = CallTraits::arg_count == (Offset + 1) && - std::is_same_v, v8::FunctionCallbackInfo const&>; + std::same_as, v8::FunctionCallbackInfo const&>; template> inline constexpr bool is_first_arg_isolate = CallTraits::arg_count != (Offset + 0) && - std::is_same_v, v8::Isolate*>; + std::same_as, v8::Isolate*>; template decltype(auto) call_from_v8_impl(F&& func, v8::FunctionCallbackInfo const& args, @@ -112,6 +110,4 @@ decltype(auto) call_from_v8(F&& func, v8::FunctionCallbackInfo const& } } -}} // namespace v8pp::detail - -#endif // V8PP_CALL_FROM_V8_HPP_INCLUDED +} // namespace v8pp::detail diff --git a/v8pp/call_v8.hpp b/v8pp/call_v8.hpp index 579915a..df91e22 100644 --- a/v8pp/call_v8.hpp +++ b/v8pp/call_v8.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_CALL_V8_HPP_INCLUDED -#define V8PP_CALL_V8_HPP_INCLUDED +#pragma once #include @@ -33,5 +32,3 @@ v8::Local call_v8(v8::Isolate* isolate, v8::Local func, } } // namespace v8pp - -#endif // V8PP_CALL_V8_HPP_INCLUDED diff --git a/v8pp/class.cpp b/v8pp/class.cpp index 4e3a259..711438c 100644 --- a/v8pp/class.cpp +++ b/v8pp/class.cpp @@ -3,7 +3,7 @@ #if !V8PP_HEADER_ONLY #include "v8pp/class.ipp" -namespace v8pp { namespace detail { +namespace v8pp::detail { template class object_registry; @@ -33,6 +33,6 @@ template object_registry& classes::find(v8::Isolate* isolate, type_info const& type); -}} // namespace v8pp::detail +} // namespace v8pp::detail #endif diff --git a/v8pp/class.hpp b/v8pp/class.hpp index 621a373..b85819a 100644 --- a/v8pp/class.hpp +++ b/v8pp/class.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_CLASS_HPP_INCLUDED -#define V8PP_CLASS_HPP_INCLUDED +#pragma once #include #include @@ -13,9 +12,7 @@ #include "v8pp/ptr_traits.hpp" #include "v8pp/type_info.hpp" -namespace v8pp { - -namespace detail { +namespace v8pp::detail { struct class_info { @@ -140,7 +137,9 @@ class classes static classes* instance(operation op, v8::Isolate* isolate); }; -} // namespace detail +} // namespace v8pp::detail + +namespace v8pp { /// Interface to access C++ classes bound to V8 template @@ -234,15 +233,13 @@ class class_ template class_& inherit() { - using namespace detail; - static_assert(std::is_base_of::value, - "Class U should be base for class T"); - //TODO: std::is_convertible and check for duplicates in hierarchy? - object_registry& base = classes::find(isolate(), type_id()); - class_info_.add_base(base, [](pointer_type const& ptr) -> pointer_type + static_assert(std::derived_from, "Class U should be base for class T"); + // TODO: std::is_convertible and check for duplicates in hierarchy? + auto& base = detail::classes::find(isolate(), detail::type_id()); + class_info_.add_base(base, [](pointer_type const& ptr) { - return pointer_type(Traits::template static_pointer_cast( - Traits::template static_pointer_cast(ptr))); + return pointer_type{Traits::template static_pointer_cast( + Traits::template static_pointer_cast(ptr))}; }); class_info_.js_function_template()->Inherit(base.class_function_template()); return *this; @@ -288,8 +285,7 @@ class class_ template class_& var(std::string_view name, Attribute attribute) { - static_assert(std::is_member_object_pointer::value, - "Attribute must be pointer to member data"); + static_assert(std::is_member_object_pointer_v, "Attribute must be pointer to member data"); v8::HandleScope scope(isolate()); @@ -308,21 +304,19 @@ class class_ template class_& property(std::string_view name, GetFunction&& get, SetFunction&& set = {}) { - using Getter = typename std::conditional< - std::is_member_function_pointer::value, + using Getter = typename std::conditional_t, typename detail::function_traits::template pointer_type, - typename std::decay::type>::type; + typename std::decay_t>; - using Setter = typename std::conditional< - std::is_member_function_pointer::value, + using Setter = typename std::conditional_t, typename detail::function_traits::template pointer_type, - typename std::decay::type>::type; + typename std::decay_t>; - static_assert(std::is_member_function_pointer::value + static_assert(std::is_member_function_pointer_v || detail::is_callable::value, "GetFunction must be callable"); - static_assert(std::is_member_function_pointer::value + static_assert(std::is_member_function_pointer_v || detail::is_callable::value - || std::is_same::value, "SetFunction must be callable"); + || std::same_as, "SetFunction must be callable"); using GetClass = std::conditional_t, T, detail::none>; using SetClass = std::conditional_t, T, detail::none>; @@ -379,18 +373,15 @@ class class_ /// Create JavaScript object which references externally created C++ class. /// It will not take ownership of the C++ pointer. - static v8::Local reference_external(v8::Isolate* isolate, - object_pointer_type const& ext) + static v8::Local reference_external(v8::Isolate* isolate, object_pointer_type const& ext) { - using namespace detail; - return classes::find(isolate, type_id()).wrap_object(ext, false); + return detail::classes::find(isolate, detail::type_id()).wrap_object(ext, false); } /// Remove external reference from JavaScript static void unreference_external(v8::Isolate* isolate, object_pointer_type const& ext) { - using namespace detail; - return classes::find(isolate, type_id()).remove_object(Traits::pointer_id(ext)); + return detail::classes::find(isolate, detail::type_id()).remove_object(Traits::pointer_id(ext)); } /// As reference_external but delete memory for C++ object @@ -398,16 +389,14 @@ class class_ /// to allocate `ext` static v8::Local import_external(v8::Isolate* isolate, object_pointer_type const& ext) { - using namespace detail; - return classes::find(isolate, type_id()).wrap_object(ext, true); + return detail::classes::find(isolate, detail::type_id()).wrap_object(ext, true); } /// Get wrapped object from V8 value, may return nullptr on fail. static object_pointer_type unwrap_object(v8::Isolate* isolate, v8::Local value) { - using namespace detail; return Traits::template static_pointer_cast( - classes::find(isolate, type_id()).unwrap_object(value)); + detail::classes::find(isolate, detail::type_id()).unwrap_object(value)); } /// Create a wrapped C++ object and import it into JavaScript @@ -418,20 +407,16 @@ class class_ } /// Find V8 object handle for a wrapped C++ object, may return empty handle on fail. - static v8::Local find_object(v8::Isolate* isolate, - object_const_pointer_type const& obj) + static v8::Local find_object(v8::Isolate* isolate, object_const_pointer_type const& obj) { - using namespace detail; - return classes::find(isolate, type_id()) - .find_v8_object(Traits::const_pointer_cast(obj)); + return detail::classes::find(isolate, detail::type_id()).find_v8_object(Traits::const_pointer_cast(obj)); } /// Find V8 object handle for a wrapped C++ object, may return empty handle on fail /// or wrap a copy of the obj if class_.auto_wrap_objects() static v8::Local find_object(v8::Isolate* isolate, T const& obj) { - using namespace detail; - detail::object_registry& class_info = classes::find(isolate, type_id()); + auto& class_info = detail::classes::find(isolate, detail::type_id()); v8::Local wrapped_object = class_info.find_v8_object(Traits::key(const_cast(&obj))); if (wrapped_object.IsEmpty() && class_info.auto_wrap_objects()) { @@ -447,22 +432,19 @@ class class_ /// Destroy wrapped C++ object static void destroy_object(v8::Isolate* isolate, object_pointer_type const& obj) { - using namespace detail; - classes::find(isolate, type_id()).remove_object(Traits::pointer_id(obj)); + detail::classes::find(isolate, detail::type_id()).remove_object(Traits::pointer_id(obj)); } /// Destroy all wrapped C++ objects of this class static void destroy_objects(v8::Isolate* isolate) { - using namespace detail; - classes::find(isolate, type_id()).remove_objects(); + detail::classes::find(isolate, detail::type_id()).remove_objects(); } /// Destroy all wrapped C++ objects and this binding class_ static void destroy(v8::Isolate* isolate) { - using namespace detail; - classes::remove(isolate, type_id()); + detail::classes::remove(isolate, detail::type_id()); } private: @@ -520,5 +502,3 @@ void cleanup(v8::Isolate* isolate); #if V8PP_HEADER_ONLY #include "v8pp/class.ipp" #endif - -#endif // V8PP_CLASS_HPP_INCLUDED diff --git a/v8pp/class.ipp b/v8pp/class.ipp index 5a4899e..28ceb49 100644 --- a/v8pp/class.ipp +++ b/v8pp/class.ipp @@ -1,10 +1,9 @@ #include "v8pp/class.hpp" +#include #include // for snprintf -namespace v8pp { - -namespace detail { +namespace v8pp::detail { static V8PP_IMPL std::string pointer_str(void const* ptr) { @@ -417,7 +416,9 @@ V8PP_IMPL classes* classes::instance(operation op, v8::Isolate* isolate) return nullptr; // should never reach this line } -} // namespace detail +} // namespace v8pp::detail + +namespace v8pp { V8PP_IMPL void cleanup(v8::Isolate* isolate) { diff --git a/v8pp/config.hpp.in b/v8pp/config.hpp.in index 11027ed..cb87f3e 100644 --- a/v8pp/config.hpp.in +++ b/v8pp/config.hpp.in @@ -1,5 +1,4 @@ -#ifndef V8PP_CONFIG_HPP_INCLUDED -#define V8PP_CONFIG_HPP_INCLUDED +#pragma once /// v8pp library version #define V8PP_VERSION "@PROJECT_VERSION@" @@ -48,5 +47,3 @@ v8::Local V8PP_PLUGIN_INIT_PROC_NAME(isolate) #define V8PP_STRINGIZE(s) V8PP_STRINGIZE0(s) #define V8PP_STRINGIZE0(s) #s - -#endif // V8PP_CONFIG_HPP_INCLUDED diff --git a/v8pp/context.hpp b/v8pp/context.hpp index 4a0c8c4..102eaeb 100644 --- a/v8pp/context.hpp +++ b/v8pp/context.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_CONTEXT_HPP_INCLUDED -#define V8PP_CONTEXT_HPP_INCLUDED +#pragma once #include #include @@ -87,7 +86,7 @@ class context template context& function(std::string_view name, Function&& func) { - using Fun = typename std::decay::type; + using Fun = typename std::decay_t; static_assert(detail::is_callable::value, "Function must be callable"); return value(name, wrap_function(isolate_, name, std::forward(func))); } @@ -119,5 +118,3 @@ class context }; } // namespace v8pp - -#endif // V8PP_CONTEXT_HPP_INCLUDED diff --git a/v8pp/convert.hpp b/v8pp/convert.hpp index 06970df..4e68aa6 100644 --- a/v8pp/convert.hpp +++ b/v8pp/convert.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_CONVERT_HPP_INCLUDED -#define V8PP_CONVERT_HPP_INCLUDED +#pragma once #include @@ -409,7 +408,7 @@ struct convert> static void get_number(v8::Isolate* isolate, v8::Local value, std::optional& result) { Number const number = v8pp::convert::from_v8(isolate, value); - if constexpr (std::is_same_v) + if constexpr (std::same_as) { result = static_cast(number); } @@ -687,7 +686,7 @@ struct convert::value>::type> { using from_type = T&; using to_type = v8::Local; - using class_type = typename std::remove_cv::type; + using class_type = typename std::remove_cv_t; static bool is_valid(v8::Isolate* isolate, v8::Local value) { @@ -721,7 +720,7 @@ struct convert, typename std::enable_if:: { using from_type = std::shared_ptr; using to_type = v8::Local; - using class_type = typename std::remove_cv::type; + using class_type = typename std::remove_cv_t; static bool is_valid(v8::Isolate*, v8::Local value) { @@ -748,7 +747,7 @@ struct convert { using from_type = T&; using to_type = v8::Local; - using class_type = typename std::remove_cv::type; + using class_type = typename std::remove_cv_t; static bool is_valid(v8::Isolate* isolate, v8::Local value) { @@ -905,5 +904,3 @@ inline invalid_argument::invalid_argument(v8::Isolate* isolate, v8::Local // for memcpy @@ -10,7 +9,7 @@ #include "v8pp/throw_ex.hpp" #include "v8pp/utility.hpp" -namespace v8pp { namespace detail { +namespace v8pp::detail { class external_data { @@ -155,14 +154,13 @@ void forward_function(v8::FunctionCallbackInfo const& args) { using FTraits = function_traits; - static_assert(is_callable::value || std::is_member_function_pointer::value, - "required callable F"); + static_assert(is_callable::value || std::is_member_function_pointer_v, "required callable F"); v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope scope(isolate); try { - if constexpr (std::is_same_v) + if constexpr (std::same_as) { invoke(args); } @@ -179,13 +177,15 @@ void forward_function(v8::FunctionCallbackInfo const& args) } } -} // namespace detail +} // namespace v8pp::detail + +namespace v8pp { /// Wrap C++ function into new V8 function template template v8::Local wrap_function_template(v8::Isolate* isolate, F&& func) { - using F_type = typename std::decay::type; + using F_type = typename std::decay_t; return v8::FunctionTemplate::New(isolate, &detail::forward_function, detail::external_data::set(isolate, std::forward(func))); @@ -197,7 +197,7 @@ v8::Local wrap_function_template(v8::Isolate* isolate, F&& template v8::Local wrap_function(v8::Isolate* isolate, std::string_view name, F&& func) { - using F_type = typename std::decay::type; + using F_type = typename std::decay_t; v8::Local fn = v8::Function::New(isolate->GetCurrentContext(), &detail::forward_function, detail::external_data::set(isolate, std::forward(func))).ToLocalChecked(); @@ -209,5 +209,3 @@ v8::Local wrap_function(v8::Isolate* isolate, std::string_view nam } } // namespace v8pp - -#endif // V8PP_FUNCTION_HPP_INCLUDED diff --git a/v8pp/json.hpp b/v8pp/json.hpp index 067b767..7787d8e 100644 --- a/v8pp/json.hpp +++ b/v8pp/json.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_JSON_HPP_INCLUDED -#define V8PP_JSON_HPP_INCLUDED +#pragma once #include @@ -29,5 +28,3 @@ v8::Local json_object(v8::Isolate* isolate, v8::Local ob #if V8PP_HEADER_ONLY #include "v8pp/json.ipp" #endif - -#endif // V8PP_JSON_HPP_INCLUDED diff --git a/v8pp/module.hpp b/v8pp/module.hpp index 8480182..41284bb 100644 --- a/v8pp/module.hpp +++ b/v8pp/module.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_MODULE_HPP_INCLUDED -#define V8PP_MODULE_HPP_INCLUDED +#pragma once #include @@ -69,7 +68,7 @@ class module template module& function(std::string_view name, Function&& func) { - using Fun = typename std::decay::type; + using Fun = typename std::decay_t; static_assert(detail::is_callable::value, "Function must be callable"); return value(name, wrap_function_template(isolate_, std::forward(func))); } @@ -93,11 +92,12 @@ class module template module& property(char const* name, GetFunction&& get, SetFunction&& set = {}) { - using Getter = typename std::decay::type; - using Setter = typename std::decay::type; + using Getter = typename std::decay_t; + using Setter = typename std::decay_t; + static_assert(detail::is_callable::value, "GetFunction must be callable"); static_assert(detail::is_callable::value - || std::is_same::value, "SetFunction must be callable"); + || std::same_as, "SetFunction must be callable"); using property_type = v8pp::property; using Traits = detail::none; @@ -163,5 +163,3 @@ class module }; } // namespace v8pp - -#endif // V8PP_MODULE_HPP_INCLUDED diff --git a/v8pp/object.hpp b/v8pp/object.hpp index 2129ef8..09c6694 100644 --- a/v8pp/object.hpp +++ b/v8pp/object.hpp @@ -1,7 +1,6 @@ -#ifndef V8PP_OBJECT_HPP_INCLUDED -#define V8PP_OBJECT_HPP_INCLUDED +#pragma once -#include +#include #include @@ -62,5 +61,3 @@ void set_const(v8::Isolate* isolate, v8::Local options, } } // namespace v8pp - -#endif // V8PP_OBJECT_HPP_INCLUDED diff --git a/v8pp/property.hpp b/v8pp/property.hpp index b7e04a0..6a546e4 100644 --- a/v8pp/property.hpp +++ b/v8pp/property.hpp @@ -1,35 +1,28 @@ -#ifndef V8PP_PROPERTY_HPP_INCLUDED -#define V8PP_PROPERTY_HPP_INCLUDED - -#include +#pragma once #include "v8pp/convert.hpp" #include "v8pp/function.hpp" -namespace v8pp { - -template -struct property; - -namespace detail { +namespace v8pp::detail { template::template arg_type<0>> inline constexpr bool function_with_object = std::is_member_function_pointer_v || (std::is_lvalue_reference_v && std::is_base_of_v>>); template> -inline constexpr bool is_getter = CallTraits::arg_count == 0 + Offset && !is_void_return; +inline constexpr bool is_getter = CallTraits::arg_count == 0 + Offset + && !std::same_as::return_type, void>; template> inline constexpr bool is_direct_getter = CallTraits::arg_count == 2 + Offset && std::is_convertible_v, v8::Local> - && std::is_same_v, v8::PropertyCallbackInfo const&> - && is_void_return; + && std::same_as, v8::PropertyCallbackInfo const&> + && std::same_as::return_type, void>; template> inline constexpr bool is_isolate_getter = CallTraits::arg_count == 1 + Offset && is_first_arg_isolate - && !is_void_return; + && !std::same_as::return_type, void>; template> inline constexpr bool is_setter = CallTraits::arg_count == 1 + Offset; @@ -37,9 +30,9 @@ inline constexpr bool is_setter = CallTraits::arg_count == 1 + Offset; template> inline constexpr bool is_direct_setter = CallTraits::arg_count == 3 + Offset && std::is_convertible_v, v8::Local> - && std::is_same_v, v8::Local> - && std::is_same_v, v8::PropertyCallbackInfo const&> - && is_void_return; + && std::same_as, v8::Local> + && std::same_as, v8::PropertyCallbackInfo const&> + && std::same_as::return_type, void>; template> inline constexpr bool is_isolate_setter = CallTraits::arg_count == 2 + Offset @@ -120,7 +113,7 @@ try { auto&& property = detail::external_data::get(info.Data()); - if constexpr (std::is_same_v) + if constexpr (std::same_as) { property_get(property.getter, name, info); } @@ -144,7 +137,7 @@ try { auto&& property = detail::external_data::get(info.Data()); - if constexpr (std::is_same_v) + if constexpr (std::same_as) { property_set(property.setter, name, value, info); } @@ -163,7 +156,9 @@ catch (std::exception const& ex) // TODO: info.GetReturnValue().Set(false); } -} // namespace detail +} // namespace v8pp::detail + +namespace v8pp { /// Property with get and set functions template @@ -228,5 +223,3 @@ struct property final }; } // namespace v8pp - -#endif // V8PP_PROPERTY_HPP_INCLUDED diff --git a/v8pp/ptr_traits.hpp b/v8pp/ptr_traits.hpp index 5a98866..012ce7d 100644 --- a/v8pp/ptr_traits.hpp +++ b/v8pp/ptr_traits.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_PTR_TRAITS_HPP_INCLUDED -#define V8PP_PTR_TRAITS_HPP_INCLUDED +#pragma once #include @@ -111,5 +110,3 @@ struct shared_ptr_traits }; } //namespace v8pp - -#endif // V8PP_PTR_TRAITS_HPP_INCLUDED diff --git a/v8pp/throw_ex.hpp b/v8pp/throw_ex.hpp index 08c4fc1..2a1e28e 100644 --- a/v8pp/throw_ex.hpp +++ b/v8pp/throw_ex.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_THROW_EX_HPP_INCLUDED -#define V8PP_THROW_EX_HPP_INCLUDED +#pragma once #include @@ -35,5 +34,3 @@ v8::Local throw_type_error(v8::Isolate* isolate, std::string_view mes #if V8PP_HEADER_ONLY #include "v8pp/throw_ex.ipp" #endif - -#endif // V8PP_THROW_EX_HPP_INCLUDED diff --git a/v8pp/type_info.hpp b/v8pp/type_info.hpp index ec66a4c..f3f3227 100644 --- a/v8pp/type_info.hpp +++ b/v8pp/type_info.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_TYPE_INFO_HPP_INCLUDED -#define V8PP_TYPE_INFO_HPP_INCLUDED +#pragma once #include @@ -64,5 +63,3 @@ constexpr type_info type_id() } } // namespace v8pp::detail - -#endif // V8PP_TYPE_INFO_HPP_INCLUDED diff --git a/v8pp/utility.hpp b/v8pp/utility.hpp index 49b8779..1fcee57 100644 --- a/v8pp/utility.hpp +++ b/v8pp/utility.hpp @@ -1,6 +1,6 @@ -#ifndef V8PP_UTILITY_HPP_INCLUDED -#define V8PP_UTILITY_HPP_INCLUDED +#pragma once +#include #include #include #include @@ -8,7 +8,7 @@ #include #include -namespace v8pp { namespace detail { +namespace v8pp::detail { template struct tuple_tail; @@ -23,6 +23,9 @@ struct none { }; +template +concept WideChar = std::same_as || std::same_as || std::same_as; + ///////////////////////////////////////////////////////////////////////////// // // is_string @@ -298,9 +301,6 @@ struct function_traits : function_traits { }; -template -inline constexpr bool is_void_return = std::is_same_v::return_type>; - template struct is_callable_impl : std::is_function::type> @@ -333,6 +333,4 @@ template using is_callable = std::integral_constant::value>::value>; -}} // namespace v8pp::detail - -#endif // V8PP_UTILITY_HPP_INCLUDED +} // namespace v8pp::detail diff --git a/v8pp/version.hpp b/v8pp/version.hpp index 9ae8a2e..6a7380f 100644 --- a/v8pp/version.hpp +++ b/v8pp/version.hpp @@ -1,5 +1,4 @@ -#ifndef V8PP_VERSION_HPP_INCLUDED -#define V8PP_VERSION_HPP_INCLUDED +#pragma once #include "v8pp/config.hpp" @@ -18,5 +17,3 @@ char const* build_options(); #if V8PP_HEADER_ONLY #include "v8pp/version.ipp" #endif - -#endif // V8PP_VERSION_HPP_INCLUDED