0

I have work on C++ with set method data type. Method is

set < string, cmp > genPerm ( const string& );

here cmp is a class

I don't know how to interpret these type of methods, from 4 hours I have search and understand the set but each time problem occurs and task is not solved. Any one help me guide me about

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 7
    Perhaps all you need is [a good reference for `std::set`](http://en.cppreference.com/w/cpp/container/set)? Or perhaps [a good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – Some programmer dude Dec 04 '17 at 10:59
  • 4
    You could add some info about *what* part you don't understand. I see `genPerm` as a function taking a `string` parameter and returning a `set`. Much like `int f(int x);`. – Bo Persson Dec 04 '17 at 11:10

1 Answers1

2

That is a function declaration of type std::set<std::string, cmp> accepting one std::string parameter by reference to const. The std::set container is also a type. So your function is of that type. The first parameter in <std::string, cmp> template determines the type of elements stored in a set which is a std::string. Set is a sorted container of unique elements. The second parameter in the set template is a key comparison function that determines how the elements are sorted. In your case the custom sorting is provided by your cmp class which probably overloads the () operator and is actually a functor. The return type of the function is:

std::set<std::string, cmp, std::allocator<std::string>>

which is equivalent to:

std::set<std::string, cmp>

If you didn't have the custom comparator cmp the return type would probably be:

std::set<std::string, std::less<std::string>, std::allocator<std::string>>

which is actually:

std::set<std::string>

for short.

Ron
  • 14,674
  • 4
  • 34
  • 47