我的任务是输出所有十位数字,其中数字不重复.我首先使用的是这样的东西:
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <functional>
using namespace std;
void Task5() {
auto initialization = [](map<int, bool> *m, int count) {
for (int i = 0; i < 10; ++i)
m[i] = true;
};
/*For cut duplicate number in map*/
auto cutting = [](map<int, bool> *m, int count, int value) {
for (int i = 9; i > count; --i)
m[count][i][value] = false;
};
/*For create copy map*/
auto mould = [](map<int,bool> *m, map<int, bool> …Run Code Online (Sandbox Code Playgroud) 我有这样的代码:
template<typename ... Args>
constexpr size_t get_init_size(Args ... args) {
return sizeof...(Args);
}
template<typename ... Args>
constexpr auto make_generic_header(Args ... args) {
constexpr size_t header_lenght = get_init_size(args...);
return header_lenght;
}
constexpr auto create_ipv4_header() {
constexpr auto x = make_generic_header(0b01, 0b10, 0b01);
return x;
}
Run Code Online (Sandbox Code Playgroud)
我知道这是虚拟代码,但我将其隔离以查找错误。
编译器给我错误(GCC):
In instantiation of 'constexpr auto make_generic_header(Args&& ...) [with Args = {int, int, int}]':
/tmp/tmp.CaO5YHcqd8/network.h:39:43: required from here
/tmp/tmp.CaO5YHcqd8/network.h:31:22: error: 'args#0' is not a constant expression
31 | constexpr size_t header_lenght = get_init_size(args...);
| ^~~~~~~~~~~~~ …Run Code Online (Sandbox Code Playgroud)