腾讯云
开发者社区
文档
建议反馈
控制台
登录/注册
首页
学习
活动
专区
圈层
工具
MCP广场
文章/答案/技术大牛
搜索
搜索
关闭
发布
文章
问答
(9999+)
视频
沙龙
2
回答
constexpr
类的设计:合并
constexpr
和非
constexpr
版本?
、
、
、
、
ConstValue(const Type& val) : _value(val) {;} const Type _value;问题1:你能确认
constexpr
版本的设计是正确的吗?问题2:如何将这两个类混合到一个名为Value的类中,该类可以是
constexpr
构造的,也可以是运行时构造的,并且其值可以在运行时或编译时为get()?编辑:问题3:如果get()是在.cpp文件中定义的
浏览 2
提问于2013-01-18
得票数 13
回答已采纳
1
回答
Constexpr
函数中的
constexpr
常量?
、
、
将cstring也定义为
constexpr
与不定义是否有任何价值、意义或区别?我的意思的一个缩写例子: #include <cstdio> { EVENT2,}; { // Does having these as
constexpr
change anything?/*
constexpr
*
浏览 18
提问于2021-01-15
得票数 2
1
回答
实现is_
constexpr
()的尝试-编译器的分歧
、
、
、
以下是基于is_
constexpr
()的's 到的三次实现尝试template <typename T>bool
constexpr
is_
constexpr
_impl_return is_
constexpr
_impl
浏览 0
提问于2019-05-21
得票数 6
回答已采纳
1
回答
拆分定义和声明时,
constexpr
不同的异常说明符
、
、
、
、
define
CONSTEXPR
_NOEXCEPT# define
CONSTEXPR
_NOEXCEPT noexceptpublicunsigned int Int(unsigned int i)
CONSTEXPR
_NOEXCEPT { } ;}; #ifdef SPLIT_
CONSTEX
浏览 1
提问于2013-04-17
得票数 0
回答已采纳
2
回答
如果基类包含数组成员,则派生类的构造函数不能是
constexpr
。
、
、
、
、
但是,当我添加一个数组时,派生的值就不能再是
constexpr
了。不过,基类的一个简单副本确实会产生
constexpr
结果。#define USE_ARRAY {
constexpr
SFoo(SFoo const&) =default;
constexpr
SFoo(SFoo
浏览 2
提问于2015-12-04
得票数 4
回答已采纳
1
回答
为什么非静态数据成员不能是
constexpr
?
、
、
这是有效的代码:
constexpr
S(int x, int y): xVal(x), yVal(y) {} const int yVal { 0 };但在这里,我真的想声明xVal和yVal
constexpr
--如下所示:
constexpr
S(int x, int y): xVal(x)
浏览 59
提问于2014-12-11
得票数 42
2
回答
在非连续成员函数上,常数的用途是什么?
、
、
中公认的答案表明,在C++14中,
constexpr
int A::a()和
constexpr
A::a() const的使用方式有所不同。也就是说,成员函数上的
constexpr
并不意味着该函数不更改它所操作的对象。给出的例子是:
constexpr
A() {}
constexpr
int b() const
constexpr
int j = a.a();
浏览 0
提问于2018-05-03
得票数 22
回答已采纳
2
回答
在构造函数上指定
constexpr
会自动使所有从构造函数创建的对象都成为
constexpr
吗?
、
、
、
下面是我的代码: public:
constexpr
int c = w + 2; // Requiresw to be
constexpr
retur
浏览 1
提问于2015-07-13
得票数 42
回答已采纳
3
回答
如何在
constexpr
上下文中使用if- string_view进行比较
、
、
、
是否有可能在std::string_view上下文中使用“
constexpr
”进行比较?s == "hello"; if
constexpr
(s == "hello") {== "hello"; if
constexpr
(s == &
浏览 4
提问于2020-10-19
得票数 4
回答已采纳
1
回答
为什么当您可以从同级函数中创建
constexpr
对象时,
constexpr
函数就不能使用同级函数呢?
、
、
、
您可以使用
constexpr
对象,但不能在
constexpr
中使用。我认为同龄人应该是某种“狭窄”的警察。consteval int consteval_sqr(int n) { return n*n; }
constexpr
int
constexpr
_sqr2(int n) { /
浏览 4
提问于2020-08-13
得票数 1
回答已采纳
3
回答
为什么不让这个核心常量表达式错误消失?
、
、
、
、
用于初始化
constexpr
变量y的核心常量表达式格式不正确。这么多都是既定的。但如果我想把if变成if
constexpr
void foo() { if
constexpr
但是,通过
constexpr
lambda进行间接定位确实有帮助:void foo(){
浏览 4
提问于2017-10-01
得票数 31
回答已采纳
1
回答
子类
constexpr
类,以获取不同的用户定义转换行为
、
、
;
constexpr
const= FractionSize;
co
浏览 5
提问于2017-12-25
得票数 0
2
回答
关于常量表达式的混淆
、
、
、
、
2, 3 }};
constexpr
int a1 = a[1];{
constexpr
std
constexpr
int bar() { return foo; } s
浏览 3
提问于2013-04-17
得票数 15
3
回答
非依赖条件下的条件常量表达式
、
、
、
假设我有一个由库的用户定义的配置函数,它可能是,也可能不是
constexpr
.
constexpr
int iterations() { return 10; }intiterations() { return std::atoi(std::getenv("ITERATIONS")); } // I'm okay with requiring the
constexpr
(),但此函数应为
constexpr
如果iterati
浏览 76
提问于2021-02-27
得票数 3
回答已采纳
1
回答
为什么不能在函数中使用
constexpr
值,但在此值的范围内可以这样做呢?
、
、
、
、
但是我不能在{ return std::array<T, il.size()>();}中使用
constexpr
-function il_to_array() print_
constexpr
<il.size()>(); // 0 - OK print_
constexpr
< size_to_size(il.size())还是非 --都不会失败,因为其中一个例子可能是
constexpr
浏览 0
提问于2016-08-13
得票数 9
回答已采纳
2
回答
在定义失败之前使用
constexpr
函数
我在
constexpr
上遇到了麻烦。“C++ Primer”一书显示了一行代码:#include <iostream>int main()
constexpr
int f = fun();std::cout << f << std:
浏览 0
提问于2015-04-03
得票数 28
回答已采纳
1
回答
C++中的
Constexpr
迭代器
、
、
、
、
我感兴趣的是为个人项目创建一个非常小的
constexpr
容器。我需要的最重要的东西是一个容器,它有真正的
constexpr
迭代器。* ptr;
constexpr
void operator--() { --ptr; }
constexpr
T const& op
浏览 1
提问于2018-10-26
得票数 3
回答已采纳
1
回答
默认生成的复制构造函数是常量表达式的规则是什么?
、
、
gcc和克朗似乎都将这些定义为
constexpr
()。现在我想知道默认生成的构造函数是常量表达式的规则是什么?struct A
constexpr
A() : i(0) {}
constexpr
intget() const { return i; } int const i;int main() { <
浏览 0
提问于2018-01-05
得票数 1
2
回答
如果有一个交警的If语句,为什么不使用其他的语句呢?
、
是否有任何理由只将if
constexpr
包括在C++17中?我可以这么做:
constexpr
int fib() { return 1; return fib<N - 1>() + fib<N - 2>();} 为什么C++委员会也没有考虑switch
constexpr
呢?template <in
浏览 0
提问于2017-08-16
得票数 14
4
回答
与定义的类具有相同类型的静态常量表达式成员
、
、
尝试1:
constexpr
Foo() {}};struct Foo { static
constexpr
Foo f;
constexpr
Foo Foo::f = Foo();现在的问题是在类定义中缺少
constexpr
成员f的初始化器。尝试3:
浏览 3
提问于2012-08-13
得票数 47
回答已采纳
点击加载更多
相关
资讯
分享一些Qt实用函数
从 C+11 升级至 C+17,它们让嵌入式系统更好了!
C++20:核心语言
从 C+98到C+17,元编程是如何演进的?
C++20 标准草案全票批准通过
热门
标签
更多标签
云服务器
ICP备案
对象存储
云点播
实时音视频
活动推荐
运营活动
广告
关闭
领券