小编ech*_*Lee的帖子

隐式将 string 转换为 string_view

void Foo1(string_view view) {
... 
}

string str = "one two three";

Foo1("one two three"); // Implicitly convert char* to string_view

Foo1(str); 

Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 我想知道哪个构造函数将 char* 隐式转换为 string_view ,哪个构造函数将字符串隐式转换为 string_view ?

我知道构造函数 (4) 将 const char* 转换为 string_view 但我传递的是 char*。

c++ string implicit-conversion string-view

7
推荐指数
1
解决办法
3万
查看次数

模板方法参数列表中“=0”

我看到如下代码:

using EnableIfIntegral = typename std::enable_if<
    std::is_integral<T>::value || std::is_enum<T>::value, int>::type;

template <typename T, EnableIfIntegral<T> = 0>
constexpr int Seconds(T n) {
  return time_internal::FromInt64(n, std::ratio<1>{});
}

template <std::intmax_t N>
constexpr int FromInt64(int64_t v, std::ratio<1, N>) {
  // Do Something
}

Run Code Online (Sandbox Code Playgroud)

我明白什么是模板函数。为什么模板参数列表中,有SomeClass<T> = 0?我知道T是模板参数。

为什么是std::ratio<1, N>参数?

c++ c++11

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

使用星型运算符的矩阵乘法

我很好奇调用 torch.mm(A, B) 和 A*B 之间有什么区别?

看起来 torch.mm 给了我们理想的结果,但 A*B 有时不起作用。

如果能提供一些文档就更好了。

谢谢你!

pytorch

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

PyTorch 张量索引或条件选择?

    for c in range(self.n_class):
        target[c][label == c] = 1
Run Code Online (Sandbox Code Playgroud)

self.n_class 是 32。目标是 32 x 1024 x 2048 张量。

我知道 target[c] 选择 1 x 1024 x 2048 中的每一个。但我不明白 [label == c]。

因为根据经验,正方形 [] 中应包含整数。

有人能解释一下第二个方块的作用以及它的意义吗?

python pytorch

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

对于包含char数组的结构,memcpy失败

struct Frame_t
{
    uint16_t src_id;
    uint16_t dst_id;
    unsigned char num;
    uint8_t is_seq;
    char data[48];
};
typedef struct Frame_t Frame;
char *convert_frame_to_char(Frame *frame)
{
    char *char_buffer = (char *)malloc(64);
    memset(char_buffer,
           0,
           64);
    memcpy(char_buffer,
           frame,
           64);
    return char_buffer;
}

Frame *convert_char_to_frame(char *char_buf)
{
    Frame *frame = (Frame *)malloc(sizeof(Frame));
    memset(frame->data,
           0,
           sizeof(char) * sizeof(frame->data));
    memcpy(frame,
           char_buf,
           sizeof(char) * sizeof(frame));
    return frame;
}
Run Code Online (Sandbox Code Playgroud)

与那些实用程序功能,如果我做

            Frame *outgoing_frame = (Frame *)malloc(sizeof(Frame));
//   outgoing_cmd->message  contains "I love you"
            strcpy(outgoing_frame->data, outgoing_cmd->message);
            outgoing_frame->src_id = outgoing_cmd->src_id; // 0
            outgoing_frame->dst_id = …
Run Code Online (Sandbox Code Playgroud)

c memcpy

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

标签 统计

c++ ×2

pytorch ×2

c ×1

c++11 ×1

implicit-conversion ×1

memcpy ×1

python ×1

string ×1

string-view ×1