我有这些课程:
#include <type_traits>
template <typename T>
class A {
public:
static_assert(std::is_default_constructible_v<T>);
};
struct B {
struct C {
int i = 0;
};
A<C> a_m;
};
int main() {
A<B::C> a;
}
Run Code Online (Sandbox Code Playgroud)
编译时,a_m不是默认可构造的,而是a可构造的。
更改C为:
struct C {
int i;
};
Run Code Online (Sandbox Code Playgroud)
一切安好。
使用 Clang 9.0.0 测试。
我很难理解这段代码发生了什么:
#include <iostream>
#include <variant>
template <class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
struct FirstPSet {
std::uint16_t uid;
};
struct SecondPSet {
std::uint16_t uid;
};
using PSet = std::variant<std::monostate, FirstPSet, SecondPSet>;
auto getUID(const PSet& pSet) {
auto visitor = overloaded{[](const std::monostate&) -> std::uint16_t { return 0; },
[](const auto& pSet) -> std::uint16_t { return pSet.uid; }};
return std::visit(visitor, pSet);
}
int main() {
FirstPSet pSet{42};
std::cout << getUID(pSet) << '\n';
} …Run Code Online (Sandbox Code Playgroud) 我们有这样的代码:
template <typename T>
struct A {
static constexpr A a = A{};
};
template <typename T>
struct B {
T a;
};
B<A<int>> b;
Run Code Online (Sandbox Code Playgroud)
GCC 13 似乎对 L.3 感到满意,但对 clang 16 不满意。
<source>:3:21: error: constexpr variable cannot have non-literal type 'const A<int>'
static constexpr A a = A{};
^
<source>:9:4: note: in instantiation of template class 'A<int>' requested here
T a;
^
<source>:12:11: note: in instantiation of template class 'B<A<int>>' requested here
B<A<int>> b;
^
<source>:3:21: note: incomplete type …Run Code Online (Sandbox Code Playgroud) 当我遇到问题时,我试图在Vim 7.3中自定义我的状态行.
我正在尝试将SVN信息放在状态行中,所以我做了类似这样的事情:
function! DrawStatusLine()
let svn = system("svn info")
let l:status = " "
let l:status = l:status . svn
let l:status = l:status . "%t" "tail of the filename
let l:status = l:status . "%*"
let l:status = l:status . "[%{strlen(&fenc)?&fenc:'none'}," "file encoding
let l:status = l:status . "%{&ff}]" "file format
let l:status = l:status . "%h" "help file flag
let l:status = l:status . "%m" "modified flag
let l:status = l:status . "%r" "read only flag
let …Run Code Online (Sandbox Code Playgroud)