#include <algorithm>
#include <cctype>
#include <functional>
#include <iostream>
#include <map>
#include <iostream>

template <typename map_type>
void verify_presence_of_key(const map_type& map, const typename map_type::key_type& checkme)
{
    auto it = map.find(checkme);

    std::cout << '"' << checkme << "\": ";

    if (it == map.end())
        std::cout << "Not found!\n";
    else
        std::cout << "Found! -- Key = \"" << it->first << "\", Value = \"" << it->second << "\".\n";
}

int main()
{
    struct caseless_less
    {
        bool operator()(const std::string& a, const std::string& b) const
        {
            auto a_ = a.begin();
            auto b_ = b.begin();

            while (a_ != a.end() && b_ != b.end())
            {
                auto lower_a = std::tolower(*a_++);
                auto lower_b = std::tolower(*b_++);

                if (lower_a < lower_b)
                    return true;

                if (lower_a > lower_b)
                    return false;
            }

            return false;
        }
    };

    std::map<std::string, unsigned, caseless_less> my_map;

    {
        std::string s = "abcd";
        unsigned val = 1;
        do {
            my_map[s] = val++;
        } while (std::next_permutation(s.begin(), s.end()));

        // remove a few to make things more interesting.
        my_map.erase("cabd");
        my_map.erase("adcb");
    }

    {
        std::string s = "AbCd";
        std::sort(s.begin(), s.end());
        do {
            verify_presence_of_key(my_map, s);
        } while (std::next_permutation(s.begin(), s.end()));
    }

}