小编emi*_*k_g的帖子

矢量和地图抛出异常

我的任务是输出所有十位数字,其中数字不重复.我首先使用的是这样的东西:

#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)

c++ c++11

4
推荐指数
1
解决办法
277
查看次数

编译器无法执行 constexpr 表达式

我有这样的代码:

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)

c++ templates constexpr c++17 constexpr-function

4
推荐指数
1
解决办法
616
查看次数

标签 统计

c++ ×2

c++11 ×1

c++17 ×1

constexpr ×1

constexpr-function ×1

templates ×1