English 中文(简体)
Return range from different sources
原标题:

I m wondering how to make same type for return value? Consider an example:

auto get_securities_by_mic(const std::string& mic)
{
    auto it = some_map.find(mic);
    // I want to write like this:
    if (it == some_map.end()) return std::views::empty<const Security&>;
    return it->second | std::views::transform([](id)->const Security&{...});
}

But it code cannot be compiled(

I came up with solution:

auto get_securities_by_mic(const std::string& mic)
{
    auto it = some_map.find(mic);
    static const std::vector<std::int64_t> empty;
    auto source = it != some_map.end() ? std::views::all(it->second) : std::views::all(empty);
    return source | std::views::transform([](id) -> const Security&{...});
}

Can I write somehow better?

问题回答

暂无回答




相关问题
Return range from different sources

I m wondering how to make same type for return value? Consider an example: auto get_securities_by_mic(const std::string& mic) { auto it = some_map.find(mic); // I want to write like this: ...

Portable branch prediction hints

Is there any portable way of doing branch prediction hints? Consider the following example: if (unlikely_condition) { /* ..A.. */ } else { /* ..B.. */ } Is this any different than ...

热门标签