... templatetypedef , , , . . , , , , , ( : !).
, , , . , , . , , / ! , , . , .
#include <bitset>
#include <vector>
using namespace std;
const int N = 4;
void addValues(int to_add, int start_pos, bitset<N> const& working, vector<bitset<N>>& values)
{
for (int i = start_pos; i < N && i <= N - to_add; ++i) {
auto working_copy(working);
working_copy[i] = 1;
if (to_add > 1) {
addValues(to_add - 1, i + 1, working_copy, values);
}
else {
values.push_back(working_copy);
}
}
}
int main(int argc, char* argv)
{
int L = 2;
vector<bitset<N>> values;
bitset<N> working;
addValues(L, 0, working, values);
return EXIT_SUCCESS;
}