#include <set>
#include <string>
#include <iostream>

struct Bar {
    Bar(std::string s) : str(s) {}
    std::string str;
};

struct Foo {
    Foo(Bar* p) : pBar(p) {}
    Bar* pBar;
};

int main() {
    auto comp = [](const Foo* f1, const Foo* f2) { return f1->pBar->str < f2->pBar->str; };
    std::set<Foo*, decltype(comp)> set_of_foos(comp);

    set_of_foos.emplace(new Foo(new Bar("x")));
    set_of_foos.emplace(new Foo(new Bar("y")));

    auto it = set_of_foos.find(new Foo(new Bar("x")));
    if (it == std::end(set_of_foos))
        std::cout << "Element not found!" << std::endl;
    else
        std::cout << "Element found: " << (*it)->pBar->str << std::endl;

	return 0;
}