feat add move_on_copy
Some checks failed
linux-arm-gcc / linux-gcc-arm (push) Failing after 2m27s
linux-arm-gcc / linux-gcc-armhf (push) Failing after 1m42s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 2m22s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 1m50s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Failing after 2m40s
linux-x64-gcc / linux-gcc (Release) (push) Failing after 2m13s

This commit is contained in:
tqcq 2024-03-31 22:55:57 +08:00
parent ed3fa45a36
commit 27ebd0d420
5 changed files with 68 additions and 19 deletions

View File

@ -43,8 +43,8 @@ jobs:
- name: install-qemu-build-deps - name: install-qemu-build-deps
if: steps.cache-qemu.outputs.cache-hit != 'true' if: steps.cache-qemu.outputs.cache-hit != 'true'
run: | run: |
sudo apt-get update sudo apt-get update -y
sudo apt-get install autoconf automake autotools-dev ninja-build sudo apt-get install -y autoconf automake autotools-dev ninja-build
- name: checkout-qemu - name: checkout-qemu
if: steps.cache-qemu.outputs.cache-hit != 'true' if: steps.cache-qemu.outputs.cache-hit != 'true'
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -62,8 +62,8 @@ jobs:
- name: arm-gnu-toolchain - name: arm-gnu-toolchain
run: | run: |
sudo apt-get update sudo apt-get update -y
sudo apt-get install g++-arm-linux-gnueabi sudo apt-get install -y g++-arm-linux-gnueabi
- name: build - name: build
run: | run: |
@ -90,8 +90,8 @@ jobs:
- name: install-qemu-build-deps - name: install-qemu-build-deps
if: steps.cache-qemu.outputs.cache-hit != 'true' if: steps.cache-qemu.outputs.cache-hit != 'true'
run: | run: |
sudo apt-get update sudo apt-get update -y
sudo apt-get install autoconf automake autotools-dev ninja-build sudo apt-get install -y autoconf automake autotools-dev ninja-build
- name: checkout-qemu - name: checkout-qemu
if: steps.cache-qemu.outputs.cache-hit != 'true' if: steps.cache-qemu.outputs.cache-hit != 'true'
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -109,8 +109,8 @@ jobs:
- name: arm-gnu-toolchain - name: arm-gnu-toolchain
run: | run: |
sudo apt-get update sudo apt-get update -y
sudo apt-get install g++-arm-linux-gnueabihf sudo apt-get install -y g++-arm-linux-gnueabihf
- name: build - name: build
run: | run: |

View File

@ -100,8 +100,7 @@ target_link_libraries(
PUBLIC rpc_core fmt marl Async++ minilua PUBLIC rpc_core fmt marl Async++ minilua
PRIVATE dl PRIVATE dl
# protobuf::libprotobuf ${WHOLE_ARCHIVE_WRAPPER_START} # protobuf::libprotobuf ${WHOLE_ARCHIVE_WRAPPER_START}
# tcmalloc_and_profiler_static # tcmalloc_and_profiler_static ${WHOLE_ARCHIVE_WRAPPER_END}
# ${WHOLE_ARCHIVE_WRAPPER_END}
) )
# set fPIC # set fPIC
@ -126,7 +125,7 @@ endif(SLED_BUILD_BENCHMARK)
function(sled_add_test) function(sled_add_test)
set(prefix SLED_TEST) set(prefix SLED_TEST)
# set(options INC_DIRS LIBS) set(options NO_MAIN)
set(one_value_keywords NAME) set(one_value_keywords NAME)
set(multi_value_keywords SRCS INC_DIRS LIBS) set(multi_value_keywords SRCS INC_DIRS LIBS)
cmake_parse_arguments("${prefix}" "${options}" "${one_value_keywords}" cmake_parse_arguments("${prefix}" "${options}" "${one_value_keywords}"
@ -148,7 +147,9 @@ function(sled_add_test)
sled/testing/test.h) sled/testing/test.h)
endif() endif()
target_include_directories(${SLED_TEST_NAME} PRIVATE ${SLED_TEST_INC_DIRS}) target_include_directories(${SLED_TEST_NAME} PRIVATE ${SLED_TEST_INC_DIRS})
target_link_libraries(${SLED_TEST_NAME} PRIVATE ${SLED_TEST_LIBS} sled) target_link_libraries(
${SLED_TEST_NAME} PRIVATE ${SLED_TEST_LIBS} sled $<$<BOOL: NOT
${SLED_TEST_NO_MAIN}>:test_main>)
add_test(NAME ${SLED_TEST_NAME} COMMAND ${SLED_TEST_NAME}) add_test(NAME ${SLED_TEST_NAME} COMMAND ${SLED_TEST_NAME})
endfunction() endfunction()
@ -176,13 +177,13 @@ if(SLED_BUILD_TESTS)
src/sled/system/fiber/fiber_test.cc src/sled/system/fiber/fiber_test.cc
src/sled/system/thread_pool_test.cc src/sled/system/thread_pool_test.cc
src/sled/rx_test.cc src/sled/rx_test.cc
src/sled/uri_test.cc src/sled/uri_test.cc)
LIBS
test_main)
sled_add_test(NAME sled_symbolize_test SRCS sled_add_test(NAME sled_symbolize_test SRCS
src/sled/debugging/symbolize_test.cc) src/sled/debugging/symbolize_test.cc NO_MAIN)
sled_add_test(NAME sled_lua_test SRCS tests/lua_test.cc LIBS test_main) sled_add_test(NAME sled_lua_test SRCS tests/lua_test.cc)
sled_add_test(NAME sled_move_on_copy_test SRCS
src/sled/utility/move_on_copy_test.cc)
endif(SLED_BUILD_TESTS) endif(SLED_BUILD_TESTS)
if(SLED_BUILD_FUZZ) if(SLED_BUILD_FUZZ)

View File

@ -62,6 +62,9 @@ namespace async {}
#include "sled/timer/timeout.h" #include "sled/timer/timeout.h"
#include "sled/timer/timer.h" #include "sled/timer/timer.h"
// utility
#include "sled/utility/move_on_copy.h"
// other // other
#include "sled/any.h" #include "sled/any.h"
#include "sled/apply.h" #include "sled/apply.h"
@ -91,4 +94,5 @@ namespace async {}
// testing // testing
#include "sled/testing/test.h" #include "sled/testing/test.h"
// debugging
#endif// SLED_SLED_H #endif// SLED_SLED_H

View File

@ -25,7 +25,8 @@ template<typename T>
auto auto
MakeMoveOnCopy(T &&value) -> MoveOnCopy<T> MakeMoveOnCopy(T &&value) -> MoveOnCopy<T>
{ {
return {std::move<T>(value)}; return {std::move(value)};
} }
}// namespace sled }// namespace sled
#endif// SLED_UTILITY_MOVE_ON_COPY_H #endif// SLED_UTILITY_MOVE_ON_COPY_H

View File

@ -0,0 +1,43 @@
#include <sled/utility/move_on_copy.h>
TEST_SUITE("MoveOnCopy")
{
TEST_CASE("Constructor imm value")
{
// immediately value
sled::MoveOnCopy<int> m(1);
auto m_copy = m;
CHECK_EQ(m_copy.value, 1);
}
TEST_CASE("Constructor implicit convert")
{
sled::MoveOnCopy<std::string> from_str("test");
auto from_str_copy = from_str;
CHECK_EQ(from_str_copy.value, "test");
CHECK_EQ(from_str.value, "");
}
TEST_CASE("Constructor from rvalue")
{
sled::MoveOnCopy<std::string> from_rvalue_std_string(std::move(std::string("test")));
auto from_rvalue_std_string_copy = from_rvalue_std_string;
CHECK_EQ(from_rvalue_std_string_copy.value, "test");
CHECK_EQ(from_rvalue_std_string.value, "");
}
TEST_CASE("Constructor(&&)")
{
sled::MoveOnCopy<std::string> from_rvalue_std_string(std::move(std::string("test")));
sled::MoveOnCopy<std::string> from_rvalue_std_string_copy(std::move(from_rvalue_std_string));
CHECK_EQ(from_rvalue_std_string_copy.value, "test");
CHECK_EQ(from_rvalue_std_string.value, "");
}
TEST_CASE("MakeMoveOnCopy")
{
auto m = sled::MakeMoveOnCopy(std::move(std::string("test")));
auto m_copy = m;
CHECK_EQ(m_copy.value, "test");
CHECK_EQ(m.value, "");
}
}