#include <iostream>
#include <map>
#include <vector>

template <typename T>
struct ChooseKfromN{
    T   mbegin;
    T   mend;
    std::vector<T> combo;
    ChooseKfromN(T first,T last,int k) : mbegin(first),mend(last),combo(k,first) {}
    bool increment(){
        for (auto it = combo.begin();it!=combo.end();it++){
            if (++(*it) == mend){
                if (it != combo.end()){
                    auto next  = it;
                    next++;
                    auto nexit = (*next);
                    nexit++;
                    std::fill(combo.begin(),next,nexit);
                }
            } else  { return true;}
        }
        std::cout << "THIS IS NEVER REACHED FOR A MAP !! \n" << std::endl;
        return false;
    }
    typename std::vector<T>::const_iterator begin(){ return combo.begin();}
    typename std::vector<T>::const_iterator end()  { return combo.end();}
};

template <typename T>
ChooseKfromN<T> createChooseKfromN(T first,T last,int k) { return ChooseKfromN<T>(first,last,k); }


int main(){
    std::vector<std::string> xx = {"A","B","C"};
    //std::map<int,int> xx;
    //xx[1] = 1;
    //xx[2] = 2;

    auto kn = createChooseKfromN(xx.begin(),xx.end(),2);
    int counter = 0;
    do {
        for (auto it = kn.begin();it != kn.end();it++){
            std::cout << (**it) << "\t";
        }
        std::cout << "\n";
        counter++;
    } while(kn.increment());
    std::cout << "counter = " << counter << "\n";
}
