5
\$\begingroup\$

This is a follow-up question for std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++ and std::deque and std::list Type Arbitrary Nested Iterable Generator Functions Implementation in C++. The only thing different in the previous implemented n_dim_vector_generator, n_dim_array_generator, n_dim_deque_generator and n_dim_list_generator functions is the type of container. After checking G. Sliepen's answer in the question Non-nested std::deque and std::list Generator Function for arithmetic_mean Function Testing in C++, I found that there is a way to implement a more generic template function n_dim_container_generator.

The usage description

For example, auto test_vector = n_dim_container_generator<std::vector, 2, 3, int>(1); is expected to create a "test_vector" object which type is std::vector<std::vector<int>>. The content of this test_vector should as same as the following code.

std::vector<int> vector1;
vector1.push_back(1);
vector1.push_back(1);
vector1.push_back(1);
std::vector<std::vector<int>> test_vector;
test_vector.push_back(vector1);
test_vector.push_back(vector1);
test_vector.push_back(vector1);

There are five key parameters in the usage of n_dim_container_generator. With the mentioned example above, the first one std::vector is the type of the container in output structure, the second one 2 represents the nested layers, the third parameter 3 represents the element count in each layer, the fourth parameter int represents the type of base elements and the final one 1 represents the base element input which would be filled in.

The experimental implementation

The experimental implementation of n_dim_container_generator template function is as follows.

template<template<class...> class Container = std::vector, std::size_t dim, std::size_t times, class T>
constexpr auto n_dim_container_generator(T input)
{
    if constexpr (dim == 0)
    {
        return input;
    }
    else
    {
        Container<decltype(n_dim_container_generator<Container, dim - 1, times, T>(input))> output;
        output.resize(times);
        std::fill(std::begin(output), std::end(output), n_dim_container_generator<Container, dim - 1, times, T>(input));
        return output;
    }
}

Test cases

With the recursive_print template function (refer to the previous question A recursive_print Function For Various Type Arbitrary Nested Iterable Implementation in C++), the n_dim_container_generator template function could be tested as the following code.

auto test_vector = n_dim_container_generator<std::vector, 2, 3, int>(1);
recursive_print(test_vector);

The output is as below.

Level 0:
 Level 1:
 1
 1
 1
 Level 1:
 1
 1
 1
 Level 1:
 1
 1
 1

In order to make sure the functionality of n_dim_container_generator, the various test cases have been implemented.

  1. The use cases of std::vector

With Boost.Test tool, the various use cases of nested std::vector structure are implemented as below.

BOOST_AUTO_TEST_CASE(vector_test_1dimension_char)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_int)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_short)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_long)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_long_long_int)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_unsigned_char)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_float)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_double)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_1dimension_long_double)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_2dimension_char)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_int)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_short)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_long)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_long_long_int)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_unsigned_char)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_float)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_double)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_2dimension_long_double)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_3dimension_char)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_int)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_short)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_long)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_long_long_int)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_unsigned_char)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_float)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_double)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_3dimension_long_double)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_4dimension_char)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_int)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_short)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_long)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_long_long_int)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_unsigned_char)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_float)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_double)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_4dimension_long_double)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_5dimension_char)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_int)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_short)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_long)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_long_long_int)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_unsigned_char)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_float)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_double)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_5dimension_long_double)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_6dimension_char)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_int)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_short)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_long)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_long_long_int)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_unsigned_char)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_float)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_double)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_6dimension_long_double)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_7dimension_char)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_int)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_short)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_long)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_long_long_int)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_unsigned_char)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_float)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_double)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_7dimension_long_double)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_8dimension_char)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_int)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_short)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_long)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_long_long_int)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_unsigned_char)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_float)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_double)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_8dimension_long_double)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}



BOOST_AUTO_TEST_CASE(vector_test_9dimension_char)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_int)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_short)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_long)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_long_long_int)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_unsigned_char)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_float)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_double)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(vector_test_9dimension_long_double)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

A Godbolt link (std::vector part) is here.

Note: The compiling output from Godbolt is <Compilation failed> and the error messages are Killed - processing time exceeded and virtual memory exhausted: Cannot allocate memory. This issue seems to be caused by Boost.Test tool is too large and the multidimensional container structure is too complex. If the enough memory and compile time resource is available, the test output is like:

Running 90 test cases...

*** No errors detected
  1. The use cases of std::deque and std::list

When it comes to the cases of std::deque and std::list, the test code can get based on the above code by replacing the keyword vector into deque and list. The result can be checked as follows.

BOOST_AUTO_TEST_CASE(deque_test_1dimension_char)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_int)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_short)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_long)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_long_long_int)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_unsigned_char)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_float)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_double)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(deque_test_1dimension_long_double)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}
BOOST_AUTO_TEST_CASE(list_test_1dimension_char)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_int)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_short)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef short TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_long)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_long_long_int)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long long int TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_unsigned_char)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef unsigned char TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_float)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef float TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_double)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE(list_test_1dimension_long_double)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef long double TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

A Godbolt link is here.

Furthermore, with Test case template with automated registration, the various element type can be listed in boost::mpl::list and the test cases can be generated automatically.

typedef boost::mpl::list<char, int, short, long, long long int, unsigned char, unsigned int, unsigned short int, unsigned long int, float, double, long double> test_types;

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_1dimension, T, test_types)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_2dimension, T, test_types)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_3dimension, T, test_types)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_4dimension, T, test_types)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_5dimension, T, test_types)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_6dimension, T, test_types)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_7dimension, T, test_types)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_8dimension, T, test_types)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_9dimension, T, test_types)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(vector_test_10dimension, T, test_types)
{
    constexpr int nested_layer = 10;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::vector, nested_layer, element_count, TestType>(input)) == 
                (n_dim_vector_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_1dimension, T, test_types)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_2dimension, T, test_types)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_3dimension, T, test_types)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_4dimension, T, test_types)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_5dimension, T, test_types)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_6dimension, T, test_types)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_7dimension, T, test_types)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_8dimension, T, test_types)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_9dimension, T, test_types)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(deque_test_10dimension, T, test_types)
{
    constexpr int nested_layer = 10;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::deque, nested_layer, element_count, TestType>(input)) == 
                (n_dim_deque_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_1dimension, T, test_types)
{
    constexpr int nested_layer = 1;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_2dimension, T, test_types)
{
    constexpr int nested_layer = 2;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_3dimension, T, test_types)
{
    constexpr int nested_layer = 3;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_4dimension, T, test_types)
{
    constexpr int nested_layer = 4;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_5dimension, T, test_types)
{
    constexpr int nested_layer = 5;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_6dimension, T, test_types)
{
    constexpr int nested_layer = 6;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_7dimension, T, test_types)
{
    constexpr int nested_layer = 7;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_8dimension, T, test_types)
{
    constexpr int nested_layer = 8;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_9dimension, T, test_types)
{
    constexpr int nested_layer = 9;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(list_test_10dimension, T, test_types)
{
    constexpr int nested_layer = 10;
    constexpr int element_count = 3;
    typedef T TestType;
    TestType input = 1;

    BOOST_TEST((n_dim_container_generator<std::list, nested_layer, element_count, TestType>(input)) == 
                (n_dim_list_generator<nested_layer, TestType>(input, element_count)));
    BOOST_TEST(true);
}

A Godbolt link is here.

All suggestions are welcome.

The summary information:

\$\endgroup\$
5
\$\begingroup\$

Template vs. function parameters

Template parameters should normally be used for things that affect the type of the result, but not for other things. The template parameter times does not affect the type of the result, so it can just be a regular function parameter:

template<template<class...> class Container = std::vector, std::size_t dim, class T>
constexpr auto n_dim_container_generator(T input, std::size_t times)
{
    if constexpr (dim == 0)
    {
        return input;
    }
    else
    {
        Container<decltype(n_dim_container_generator<Container, dim - 1, T>(input, times))> output;
        output.resize(times);
        std::fill(std::begin(output), std::end(output), n_dim_container_generator<Container, dim - 1, T>(input, times));
        return output;
    }
}

Avoid unnecessary default initialization

By calling output.resize(times), you force the container to default construct all elements, right before you overwrite all elements. The solution is to use reserve() instead, and push_back() the elements you want to add:

output.reserve(times);
std::fill_n(std::back_inserter(output), times, n_dim_container_generator<Container, dim - 1, T>(input, times));

Avoid repetition

You are repeating the recursive call to the function with dim - 1 twice, once to get its return type and once to actually get a value. You can avoid the repetition by just getting a value first:

auto element = n_dim_container_generator<Container, dim - 1, T>(input, times);
Container<decltype(element)> output;
output.reserve(times);
std::fill_n(std::back_inserter(output), times, element);

Make use of the constructors that fill the container for you

The constructors of std::vector, std::list and std::deque all have an overload that take a count and a const T &element as an argument, and will construct a container with the given element repeated count times. That's exactly what you are trying to do manually. So you can just make use of those constructors and write:

template<template<class...> class Container = std::vector, std::size_t dim, class T>
constexpr auto n_dim_container_generator(T input, std::size_t times)
{
    if constexpr (dim == 0)
    {
        return input;
    }
    else
    {
        return Container(times, n_dim_container_generator<Container, dim - 1, T>(input, times));
    }
}

Non-deducible template parameters without a default value must come before template parameters with a default value

You gave the template parameter Container a default value, but you can actually never write something like:

auto data = n_dim_container_generator<2>(1, 3);

To fix this, make sure std::size_t dim comes first:

template<std::size_t dim, template<class...> class Container = std::vector, class T>
\$\endgroup\$
2
  • \$\begingroup\$ My first interpretation of "repeating the call" was that the run-time work was being performed twice, rather than repeating the source code for it in non-evaluated context as argument to decltype(). I wish I could suggest a better wording for that. \$\endgroup\$ – Toby Speight Dec 4 '20 at 15:27
  • \$\begingroup\$ @TobySpeight Maybe "call expression"? But yeah, I couldn't find something better either. \$\endgroup\$ – G. Sliepen Dec 4 '20 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.