给定一对传统的“开始”和“结束”迭代器,如何创建与 range-v3 兼容的范围?
假设我正在编写一个接受两个迭代器的通用函数,以便与遗留代码兼容。
struct result;
bool keep_line(const std::string&);
result parse_line(const std::string&);
template <typename InputIt>
std::vector<result> parse_lines(InputIt begin, InputIt end)
{
// This is what I want to do...
auto lines = ranges::make_range_out_of_legacy_iterators(begin, end);
return lines
| ranges::view::filter(keep_line)
| ranges::view::transform(parse_line)
| ranges::to<std::vector<result>>();
}
Run Code Online (Sandbox Code Playgroud) 我想定义一个概念,指示类型是几种受支持的类型之一。我可以通过重复列出类型来做到这一点std::same_as<T, U>
:
#include <concepts>
template <typename T>
concept IsMySupportedType = std::same_as<T, int32_t> || std::same_as<T, int64_t> || std::same_as<T, float> || std::same_as<T, double>;
Run Code Online (Sandbox Code Playgroud)
有没有更简洁的方式来写这个而不重复这个std::same_as
概念?
我有一个项目,其中包含一个核心库(LibA
在下面的示例中)、一个可执行文件和一个LibB
依赖于第一个库的第二个库 ( )。第二个库 ( LibB
) 始终以共享(动态库)形式构建。
有什么办法,我可以强制LibB
到永远压连杆共享的版本LibA
?
这是一个CMakeLists.txt
说明问题的小文件:
cmake_minimum_required(VERSION 3.16)
project(my_project LANGUAGES CXX)
# LibA should be buildable in either static or shared form.
add_library(LibA A.cpp)
# In the real case, there are many customizations to `LibA`:
# compile flags, include dirs, target properties, etc.
add_executable(ExecutableA main.cpp)
target_link_libraries(ExecutableA LibA)
# I want library myB to *always* link against the dynamic library libLibA.so.
add_library(LibB SHARED B.cpp) …
Run Code Online (Sandbox Code Playgroud)