#define OPTION_1

#ifdef OPTION_1

#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <string.h>

enum {
    EXTENSIONTAG_PCX,
    EXTENSIONTAG_MNG,
    EXTENSIONTAG_SMK
};

int main()
{  
    constexpr std::array<std::pair<const char*, int>, 4> extensions {{
        {"pcx", EXTENSIONTAG_PCX},
        {"mng", EXTENSIONTAG_MNG},
        {"png", EXTENSIONTAG_MNG},
        {"smk", EXTENSIONTAG_SMK}
    }};

    for(const std::string file_extension : {"pcx", "mng", "png", "smk", "evil"}) {
        try {
            const auto found = std::find_if(extensions.cbegin(), extensions.cend(), [&file_extension](const std::pair<const char*, int>& p) {
                return strcmp(file_extension.c_str(), p.first) == 0;
            });

            if(found != extensions.cend()) {
                //bn_int_tag_set(&extensiontag, found->second);
                std::cout << "extension: " << found->first << ", tag: " << found->second << '\n';
            } else {
                throw std::runtime_error("Unknown file extension (" + file_extension + ")");
            }
        } catch (const std::exception& e) {
            std::cerr << e.what() << '\n';
        }
    }
}

#else

#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <string.h>

enum {
    EXTENSIONTAG_PCX,
    EXTENSIONTAG_MNG,
    EXTENSIONTAG_SMK
};

int main()
{
    auto cmp = [](const char* lhs, const char* rhs) { return strcmp(lhs, rhs) < 0; };

    const std::map<const char*, int, decltype(cmp)> extensions {{
        {"pcx", EXTENSIONTAG_PCX},
        {"mng", EXTENSIONTAG_MNG},
        {"png", EXTENSIONTAG_MNG},
        {"smk", EXTENSIONTAG_SMK}
    }, cmp};

    for(const std::string file_extension : {"pcx", "mng", "png", "smk", "evil"}) {
        try {
            // if custom exception is not needed
            //bn_int_tag_set(&extensiontag, extensions.at(file_extension.c_str()));

            // else
            const auto found = extensions.find(file_extension.c_str());
            if(found != extensions.cend()) {
                //bn_int_tag_set(&extensiontag, found->second);
                std::cout << "extension: " << found->first << ", tag: " << found->second << '\n';
            } else {
                throw std::runtime_error("Unknown file extension (" + file_extension + ")");
            }

        } catch (const std::exception& e) {
            std::cerr << e.what() << '\n';
        }
    }
}

#endif
