Skip to content

[clang-tidy] Check request: modernize-use-ctad-to-construct-heterogenous-containers #121295

@denzor200

Description

@denzor200

C++17 suggests us a way to invoke templated class constructor without explicit template arguments specification.
Without that feature we had to use special wrappers like std::make_pair and std::make_tuple, so we don't want them anymore(except the case when std::reference_wrapper passed).

extern int a;
extern int b;
auto t1 = std::make_tuple(a, b);           // INCORRECT
auto t2 = std::tuple{a, b};                // OK
auto p1 = std::make_pair(a, b);            // INCORRECT
auto p2 = std::pair{a, b};                 // OK
auto t3 = std::make_tuple(std::ref(a), b); // OK because of `std::reference_wrapper`
auto p3 = std::make_pair(std::cref(a), b); // OK the same reason

Bear in mind that this check should not work with generic types, because it's impossible to know is that types are reference wrappers:

template<typename T>
void process(T a, int b) {
    auto p1 = std::make_pair(a, b);                   // OK
    auto p2 = std::make_pair(static_cast<int>(a), b); // INCORRECT, should be changed to `std::pair{static_cast<int>(a), b}`
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions