Dlaczego ustawiono :: znajdź nie szablon?

Z funkcjami szablonu z<algorithm> możesz robić takie rzeczy

struct foo
{
    int bar, baz;
};

struct bar_less
{
    // compare foo with foo
    bool operator()(const foo& lh, const foo& rh) const
    {
        return lh.bar < rh.bar;
    }
    template<typename T>  // compare some T with foo
    bool operator()(T lh, const foo& rh) const
    {
        return lh < rh.bar;
    }
    template<typename T>  // compare foo with some T
    bool operator()(const foo& lh, T rh) const
    {
        return lh.bar < rh;
    }
};

int main()
{
    foo foos[] = { {1, 2}, {2, 3}, {4, 5} };
    bar_less cmp;
    int bar_value = 2;
    // find element {2, 3} using an int
    auto it = std::lower_bound(begin(foos), end(foos), bar_value, cmp);
    std::cout << it->baz;
}

Wstd::set metody takie jakfind musisz przekazać obiekt typuset::key_type co często zmusza cię do utworzenia obiektu fikcyjnego.

set<foo> foos;
foo search_dummy = {2,3};  // don't need a full foo object;
auto it = foos.find(search_dummy);

Byłoby bardzo pomocne, gdyby można było zadzwonić po prostufoos.find(2). Czy jest jakiś powódfind nie może być szablonem, akceptującym wszystko, co można przekazać do mniejszego predykatu. A jeśli po prostu brakuje, dlaczego nie jest w C ++ 11 (myślę, że tak nie jest).

Edytować

Główne pytanie brzmi: DLACZEGO nie jest możliwe, a jeśli to możliwe, DLACZEGO postanowił standard nie zapewniać. Drugie pytanie, które możesz zaproponować obejścia :-) (boost::multi_index_container w tej chwili przychodzi mi do głowy, co zapewnia ekstrakcję kluczy z typów wartości)

Inny przykład z droższym typem konstrukcji. Kluczname jest częścią typu i nie powinna być używana jako kopia w kluczu map;

struct Person
{
    std::string name;
    std::string adress;
    std::string phone, email, fax, stackoferflowNickname;
    int age;
    std::vector<Person*> friends;
    std::vector<Relation> relations;
};

struct PersonOrder
{
    // assume that the full name is an unique identifier
    bool operator()(const Person& lh, const Person& rh) const
    {
        return lh.name < rh.name;
    }
};

class PersonRepository
{
public:

    const Person& FindPerson(const std::string& name) const
    {
        Person searchDummy;  // ouch
        searchDummy.name = name;
        return FindPerson(searchDummy);
    }

    const Person& FindPerson(const Person& person) const;

private:
    std::set<Person, PersonOrder> persons_;
    // what i want to avoid
    // std::map<std::string, Person> persons_;
    // Person searchDummyForReuseButNotThreadSafe;

};

questionAnswers(5)

yourAnswerToTheQuestion