以下不能在 CentOS 7 上的 g++ 8.1.0 下编译:
嘿.h
#pragma once
#include <iostream>
#include <type_traits>
class Valid {};
class Invalid {};
struct Hey
{
template<typename T>
static constexpr bool is_valid() { return std::is_same_v<T, Valid>; }
template<typename T, std::enable_if_t<is_valid<T>()>* = nullptr>
void howdy() const;
};
template<typename T, std::enable_if_t<Hey::is_valid<T>()>*>
void Hey::howdy() const
{
std::cout << "Howdy" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
编译器输出:
In file included from hey.cpp:1:
hey.h:18:8: error: no declaration matches ‘void Hey::howdy() const’
void Hey::howdy() const
^~~
hey.h:14:10: note: candidate is: ‘template<class T, …Run Code Online (Sandbox Code Playgroud) 我不明白在标准中包含std :: nullopt_t的原因.它是否仅为方便起见而存在,还是在某些利基环境中需要?
为了清楚起见,我理解它被用作构造空std :: optional对象的参数.但是考虑到std :: optional的默认构造函数已经存在,似乎没有明显的动机存在std :: nullopt_t.对于std :: optional,是否必须存在这样的构造函数和赋值运算符以符合特定的概念?如果是这样,哪个概念?