ResInsight icon indicating copy to clipboard operation
ResInsight copied to clipboard

Use concepts to avoid multiple overrides of different containers

Open magnesj opened this issue 2 years ago • 0 comments

RiaSummaryAddressAnalyzer has two functions

    void appendAddresses( const std::set<RifEclipseSummaryAddress>& allAddresses );
    void appendAddresses( const std::vector<RifEclipseSummaryAddress>& allAddresses );

These can be replaced by a single function using concepts.

Suggested solution Define a concept for an input range of a specific type. This allows any container type to be used as input argument, like std::vector<T>, std::set<T>, ... Inspired by https://www.reedbeta.com/blog/ranges-compatible-containers/

template <typename R, typename T>
concept input_range_of = std::ranges::input_range<R> && std::convertible_to<std::ranges::range_value_t<R>, T>;

void appendAddresses_concept( input_range_of<RiaSummaryCurveAddress> auto&& addresses );

magnesj avatar Sep 20 '23 06:09 magnesj