diff --git a/cmake/subdir.cmake b/cmake/subdir.cmake index 02013f980..3cddaf591 100644 --- a/cmake/subdir.cmake +++ b/cmake/subdir.cmake @@ -22,10 +22,6 @@ endif() foreach(child ${children}) get_filename_component(subdir_name ${child} NAME) string(TOUPPER ${subdir_name} subdir_name) - if((${subdir_name} STREQUAL "STRUCT_PACK" OR ${subdir_name} STREQUAL "STRUCT_PB") AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")) - message(STATUS "skip ${subdir_name}") - continue() - endif() if (BUILD_${subdir_name}) message(STATUS "BUILD_${subdir_name}: ${BUILD_${subdir_name}}") diff --git a/include/ylt/reflection/member_count.hpp b/include/ylt/reflection/member_count.hpp index 3932c580d..837831748 100644 --- a/include/ylt/reflection/member_count.hpp +++ b/include/ylt/reflection/member_count.hpp @@ -11,7 +11,10 @@ #endif #include "user_reflect_macro.hpp" - +namespace struct_pack { +template +struct compatible; +} namespace ylt::reflection { template using remove_cvref_t = std::remove_cv_t>; @@ -25,9 +28,7 @@ concept expected = requires(Type e) { e.has_value(); e.error(); requires std::is_same_v::value_type> || - requires(Type e) { - e.value(); - }; + requires(Type e) { e.value(); }; }; #else template @@ -71,9 +72,8 @@ constexpr bool optional = !expected && optional_impl::value; namespace internal { #if __cpp_concepts >= 201907L template -concept tuple_size = requires(Type tuple) { - std::tuple_size>::value; -}; +concept tuple_size = + requires(Type tuple) { std::tuple_size>::value; }; #else template struct tuple_size_impl : std::false_type {}; @@ -87,14 +87,12 @@ template constexpr bool tuple_size = tuple_size_impl::value; #endif -template -struct compatible; - template constexpr inline bool is_compatible_v = false; template -constexpr inline bool is_compatible_v> = true; +constexpr inline bool is_compatible_v> = + true; struct UniversalVectorType { template diff --git a/include/ylt/reflection/member_ptr.hpp b/include/ylt/reflection/member_ptr.hpp index fec004ec9..1fa090e9d 100644 --- a/include/ylt/reflection/member_ptr.hpp +++ b/include/ylt/reflection/member_ptr.hpp @@ -3,7 +3,7 @@ // modified based on: // https://github.com/getml/reflect-cpp/blob/main/include/rfl/internal/bind_fake_object_to_tuple.hpp -// thanks for alxn4's greate idea! +// thanks for alxn4's great idea! namespace ylt::reflection { namespace internal { diff --git a/include/ylt/struct_pack.hpp b/include/ylt/struct_pack.hpp index 9e3d229fc..f05e9cd53 100644 --- a/include/ylt/struct_pack.hpp +++ b/include/ylt/struct_pack.hpp @@ -398,6 +398,8 @@ template < typename = std::enable_if_t>> #endif [[nodiscard]] auto deserialize(const View &v) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), v); if SP_UNLIKELY (errc) { @@ -408,6 +410,8 @@ template < template [[nodiscard]] auto deserialize(const char *data, size_t size) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; if (auto errc = deserialize_to(ret.value(), data, size); errc) { ret = unexpected{errc}; @@ -421,6 +425,8 @@ template >> #endif [[nodiscard]] auto deserialize(Reader &v) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), v); if SP_UNLIKELY (errc) { @@ -435,6 +441,8 @@ template template #endif [[nodiscard]] auto deserialize(const View &v, size_t &consume_len) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), v, consume_len); if SP_UNLIKELY (errc) { @@ -446,6 +454,8 @@ template template [[nodiscard]] auto deserialize(const char *data, size_t size, size_t &consume_len) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), data, size, consume_len); if SP_UNLIKELY (errc) { @@ -463,6 +473,8 @@ template < typename = std::enable_if_t>> #endif [[nodiscard]] auto deserialize(const View &v) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), v); if SP_UNLIKELY (errc) { @@ -487,6 +499,8 @@ template >> #endif [[nodiscard]] auto deserialize(Reader &v) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), v); if SP_UNLIKELY (errc) { @@ -502,6 +516,8 @@ template #endif [[nodiscard]] auto deserialize(const View &v, size_t &consume_len) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), v, consume_len); if SP_UNLIKELY (errc) { @@ -513,6 +529,8 @@ template template [[nodiscard]] auto deserialize(const char *data, size_t size, size_t &consume_len) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to(ret.value(), data, size, consume_len); if SP_UNLIKELY (errc) { @@ -527,6 +545,8 @@ template template #endif [[nodiscard]] auto deserialize_with_offset(const View &v, size_t &offset) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to_with_offset(ret.value(), v, offset); if SP_UNLIKELY (errc) { @@ -538,6 +558,8 @@ template template [[nodiscard]] auto deserialize_with_offset(const char *data, size_t size, size_t &offset) { + static_assert(sizeof...(Args) > 0, + "the correct code is struct_pack::deserialize();"); expected, struct_pack::err_code> ret; auto errc = deserialize_to_with_offset(ret.value(), data, size, offset); if SP_UNLIKELY (errc) { diff --git a/src/struct_pack/tests/test_many_members.cpp b/src/struct_pack/tests/test_many_members.cpp index 44a4e7807..ea00c1526 100644 --- a/src/struct_pack/tests/test_many_members.cpp +++ b/src/struct_pack/tests/test_many_members.cpp @@ -3,6 +3,7 @@ #include "doctest.h" #include "ylt/struct_pack.hpp" #include "ylt/struct_pack/type_calculate.hpp" +// struct_pack support 255 member max struct many_members { int a1; std::string b1; @@ -128,6 +129,8 @@ struct many_members { std::string b61; int a62; std::string b62; +#ifndef _MSC_VER + // too many variable may cause msvc OOM, disable least variables int a63; std::string b63; int a64; @@ -259,6 +262,7 @@ struct many_members { int a127; std::string b127; int a128; +#endif }; struct many_members2 : public many_members {}; STRUCT_PACK_REFL(many_members2, a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, @@ -270,9 +274,13 @@ STRUCT_PACK_REFL(many_members2, a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, a6, b6, a38, b38, a39, b39, a40, b40, a41, b41, a42, b42, a43, b43, a44, b44, a45, b45, a46, b46, a47, b47, a48, b48, a49, b49, a50, b50, a51, b51, a52, b52, a53, b53, a54, b54, a55, b55, - a56, b56, a57, b57, a58, b58, a59, b59, a60, b60, a61, b61, - a62, b62); + a56, b56, a57, b57, a58, b58, a59, b59, a60, b60); TEST_CASE("test many members") { - CHECK(struct_pack::get_type_literal().size() == 384); - CHECK(struct_pack::get_type_literal().size() == 188); + int size = 384; + +#ifdef _MSC_VER + size = 188; +#endif + CHECK(struct_pack::get_type_literal().size() == size); + CHECK(struct_pack::get_type_literal().size() == 182); } \ No newline at end of file diff --git a/test.cpp b/test.cpp deleted file mode 100644 index a41527120..000000000 --- a/test.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -using namespace std; -string i1 = "else if constexpr (Count == "; -string j = " ){ return visitor("; -string l = ");}"; -int main() { - std::string list = "_SPG0(o)"; - for (int i = 2; i <= 256; ++i) { - list += ",_SPG" + to_string(i - 1) + "(o)"; - cout << i1 + to_string(i) + j + list + l << endl; - } - return 0; -} diff --git a/test_install.sh b/test_install.sh deleted file mode 100644 index ca70d52ce..000000000 --- a/test_install.sh +++ /dev/null @@ -1,67 +0,0 @@ -# -# Copyright (c) 2023, Alibaba Group Holding Limited; -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -set -e -echo "test yaLanTingLibs install" -rm -rf tmp -mkdir tmp -cd tmp -echo "copy test code" -prj_list="struct_pack struct_pb coro_rpc easylog" -for lib in $prj_list -do - mkdir "$lib" - echo " copy $lib" - cp -r ../src/"$lib"/tests "$lib"/ -done -cp -r ../thirdparty/doctest . -cp -r ../src/struct_pb/conformance struct_pb/ -echo "add CMakeLists.txt" -prj_file=CMakeLists.txt -( -cat << EOF -cmake_minimum_required(VERSION 3.15) -project(yaLanTingLibs_install_tests - VERSION 1.0.0 - LANGUAGES CXX - ) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -enable_testing() -find_package(Threads REQUIRED) -find_package(OpenSSL) -find_package(yalantinglibs REQUIRED) -add_compile_definitions(ASYNC_SIMPLE_HAS_NOT_AIO) -############################# -# doctest -############################# -add_library(doctest INTERFACE) -target_include_directories(doctest INTERFACE doctest) -EOF -) > $prj_file -for lib in $prj_list -do - echo "add_subdirectory($lib/tests)" >> $prj_file -done -echo "add_subdirectory(struct_pb/conformance)" >> $prj_file -# workaround -cp -r ../src/struct_pack/benchmark struct_pack/ -echo "target_include_directories(test_struct_pb PUBLIC struct_pack/benchmark)" >> $prj_file - -echo "build tests" -cmake -B build -S . -DCMAKE_PREFIX_PATH="$(pwd)/../installed" -cmake --build build -j -echo "run tests" -cd build && ctest