小编sup*_*nun的帖子

为受约束的 std::tuple 专门化 std::hash 是否被视为未定义行为?

我知道专门std::hash针对将军std::tuple是未定义的行为。

\n

但是,如果专门std::hash针对特定的元组呢?

\n

例如,

\n
namespace std {\n  template<>\n  struct hash<std::tuple<MyType, float>> {\n    size_t operator()(const std::tuple<MyType, float>& t) const {\n        // ...\n    } \n  };\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

或者甚至std::tuple<Ts ...>使用某种required is_all_same_as_v<Ts\xe2\x80\xa6, MyType>C++20 约束来确保元组中的所有类型都完全相同MyType

\n

例如,这个

\n
namespace std {\n  template<typename... Ts>\n    requires (sizeof...(Ts) > 0 && is_all_same_as_v<Ts..., MyType>)\n  struct hash<std::tuple<Ts...>> {\n    size_t operator()(const std::tuple<Ts...>& t) const {\n        // ...\n    } \n  };\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

仍然被认为是未定义的行为吗?如果是这样,为什么?

\n

编辑:确保检查参数包的大小至少为 1,以避免专门化,std::hash<std::tuple<>> …

c++ c++20

9
推荐指数
1
解决办法
327
查看次数

带有下划线的十六进制值语法是什么意思?例如:参数FOO = 20'h0002_0

几乎只是标题.这个下划线是什么意思?这有什么不同于:

parameter FOO = 20'h00020;
Run Code Online (Sandbox Code Playgroud)

我不知道该找什么来寻找这个问题的答案,因为我不知道这种语法是什么.

parameters syntax verilog

6
推荐指数
1
解决办法
1757
查看次数

在systemverilog中使用初始块与初始化reg变量有什么区别?

以下两个关于模拟的例子有什么区别?

一个)

reg a;
initial a = 1'b0;
Run Code Online (Sandbox Code Playgroud)

B)

reg a = 1'b0;
Run Code Online (Sandbox Code Playgroud)

逻辑变量是不同的?

simulation verilog system-verilog

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

为什么默认可构造的类型在某些情况下会提高性能?

考虑这三个类:

struct Foo
{
    // causes default ctor to be deleted
    constexpr explicit Foo(int i) noexcept : _i(i) {} 
private:
    int _i;
};

// same as Foo but default ctor is brought back and explicitly defaulted
struct Bar
{
    constexpr Bar() noexcept = default;
    constexpr explicit Bar(int i) noexcept : _i(i) {}

private:
    int _i;
};

// same as Bar but member variable uses brace-or-equals initializer (braces in this case)
struct Baz
{
    constexpr Baz() noexcept = default;
    constexpr explicit …
Run Code Online (Sandbox Code Playgroud)

c++ c++20

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

标签 统计

c++ ×2

c++20 ×2

verilog ×2

parameters ×1

simulation ×1

syntax ×1

system-verilog ×1