#include <iostream>
#include <vector>
#include <functional>
#include <cinttypes>

using namespace std;

template<class T, uint8_t B>
struct Hui {
    static void sort3_impl(vector<T> & arr);
};

template<class T>
struct Hui<T, 0> {
    static void sort3_impl(vector<T> &)
    {
    }
};

template<class T>
struct Hui<T, 1> {
    static void sort3_impl(vector<T> & arr)
    {
        swap(arr[0], arr[1]);
    }
};

template<class T>
struct Hui<T, 2> {
    static void sort3_impl(vector<T> & arr)
    {
        swap(arr[1], arr[2]);
    }
};

template<class T>
struct Hui<T, 5> {
    static void sort3_impl(vector<T> & arr)
    {
        swap(arr[0], arr[1]);
        swap(arr[1], arr[2]);
    }
};

template<class T>
struct Hui<T, 6> {
    static void sort3_impl(vector<T> & arr)
    {
        swap(arr[0], arr[2]);
        swap(arr[1], arr[2]);
    }
};

template<class T>
struct Hui<T, 7> {
    static void sort3_impl(vector<T> & arr)
    {
        swap(arr[0], arr[2]);
    }
};

template<class T>
void sort3_runtime_call(vector<T> & arr, uint8_t bits)
{
    static array<function<void(vector<T> &)>, 8> func_table = {
        Hui<T, 0>::sort3_impl,
        Hui<T, 1>::sort3_impl,
        Hui<T, 2>::sort3_impl,
        Hui<T, 0>::sort3_impl,
        Hui<T, 0>::sort3_impl,
        Hui<T, 5>::sort3_impl,
        Hui<T, 6>::sort3_impl,
        Hui<T, 7>::sort3_impl,
    };
    func_table[bits](arr);
}

template<class T>
void sort3(vector<T> & arr)
{
    sort3_runtime_call(arr, (arr[0] > arr[1]) | ((arr[1] > arr[2]) << 1) | ((arr[0] > arr[2]) << 2));
}

int main()
{
    vector<vector<uint32_t>> tests = {
        {1, 2, 3}, {1, 3, 2}, {2, 1, 3},
        {2, 3, 1}, {3, 1, 2}, {3, 2, 1},
    };

    for (auto && arr : tests) {
        sort3(arr);
        cout << arr[0] << ", " << arr[1] << ", " << arr[2] << endl;
    }
    return EXIT_SUCCESS;
}