小编jwm*_*jwm的帖子

我如何建议在 Markdown 中更改多行

我第一次在 GitHub 上遇到“建议”代码块,标识为

```suggestion
change
```
Run Code Online (Sandbox Code Playgroud)

这可以用栅栏内的线替换之前的线。但是如果我想替换多行怎么办?

我想这是可能的,但我在任何地方都找不到此功能的文档。我至少了解到要使用的关键术语是围栏代码块信息字符串,但我能想到的最好的办法是信息字符串(第一个标记除外)未指定。

此功能是否已在任何地方记录?它在代码审查中非常有用。

编辑:这是一个 Markdown 问题,而不是 GitHub 问题

到目前为止,它似乎是 GitHub 独有的功能。这可能是答案,但告诉我如何使用 GitHub GUI 并不能解决问题

markdown github-flavored-markdown

58
推荐指数
2
解决办法
3万
查看次数

我应该如何使std :: filesystem显示符合Visual Studio 2015的标准

我有一个目前锁定在Visual Studio 2015中的项目.但是,我想编写符合标准的代码.

我想使用std::filesystem它,但直到C++ - 17才进入标准.幸运的是,几乎所有东西都可用,就在std::experimental::filesystem::v1命名空间中.我不喜欢一揽子using指令; 我更喜欢将事情做好,以明确事情的来源.所以我不打算在全球范围内using发表声明.需要一些魔法才能说服编译器按我的意愿行事.

这是我的第一次尝试:

#include <filesystem>
#if defined(_MSC_VER) && _MSC_VER <= 1900 // VS 2015
namespace std {
    namespace filesystem {
        using path = std::experimental::filesystem::v1::path;
    }
}
#endif
Run Code Online (Sandbox Code Playgroud)

这很好用,std::filesystem::path现在可以访问.我测试了创建和使用path对象,它的工作原理.

随着我前进,我知道我将需要更多的东西.我想知道是否有办法引入整个事情:

namespace std {
    namespace filesystem {
        using std::experimental::filesystem::v1;
    }
}
Run Code Online (Sandbox Code Playgroud)

这似乎是倒退了一步.似乎没有任何东西可见.事后来看,我认为这是有道理的,因为using语句的范围以下一行的右括号结束.

接下来,我想得到一个directory_entry.同样的技术似乎有效

namespace std {
    namespace filesystem {
        using directory_entry = std::experimental::filesystem::v1::directory_entry;
    }
}
Run Code Online (Sandbox Code Playgroud)

再次,编译器似乎很高兴.

现在,我想用std::directory::create_directories.但是,这是一个函数,而不是一个类,所以相同的技术将无法工作.

我认为这std::function …

c++ visual-studio-2015 std-filesystem

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

可变递归模板

我有一个特殊的格式,需要使用空格分隔的标记和最终的空终止符(null是输出的一部分).我创建了一个函数来将一系列以空格分隔的标记发送到输出流:

// C++ variadic template function to output tokens to a stream delimited by spaces
template <typename T>
void join(std::ostream& os, T const& arg)
{
  // This is the last argument, so insert a null in the stream to delimit
  os << arg << '\000';
}

// Join one, add a space, try again.
template <typename T, typename... Args>
void join(std::ostream& os, T const& arg, Args... args)  // recursive variadic function
{
  os << arg << " ";
  join(os, args...); …
Run Code Online (Sandbox Code Playgroud)

c++ templates variadic-templates c++11 c++14

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

用Streambuilder替换jsoncpp FastWriter的方法是什么?

我有一个要序列化的jsoncpp值。最直接的方法是这样的:

Json::Value val; // population is left as an exercise for the reader

std::string str = Json::FastWriter().write(val);
Run Code Online (Sandbox Code Playgroud)

问题是它FastWriter已被弃用,我不能容忍编译器警告。根据不太直观的文档,我应该StreamWriterBuilder改用:

Json::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = "";
std::unique_ptr<Json::StreamWriter> writer( builder.newStreamWriter() );
std::ostringstream os;
writer->write(val, &os);
std::string str = os.str();
Run Code Online (Sandbox Code Playgroud)

这肯定不能“更好”吗?我假设错误在于我,并且有一种简单的方法来执行最小序列化(没有多余的空格)。

显示了一个稍微更紧凑的形式(尽管它似乎只是将上面的内容包装在一个函数调用中)。

Json::StreamWriterBuilder builder;
builder["indentation"] = "";  // assume default for comments is None
std::string str = Json::writeString(builder, val);
Run Code Online (Sandbox Code Playgroud)

现在是正确的方法吗?

c++ tostring jsoncpp

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

CMake check_function_exists没有

我正在完成CMake教程并与相关的项目文件进行交叉检查,我坚持第4步.

说明将这些行添加到顶级CMakeLists.txt文件中:

# does this system provide the log and exp functions?
include (CheckFunctionExists)
check_function_exists (log HAVE_LOG)
check_function_exists (exp HAVE_EXP)
Run Code Online (Sandbox Code Playgroud)

如上所述,这是一个微不足道的测试,因为地球上的每个系统都具有logexp.但它失败了.生成Makefile时,我明白了

-- Looking for log
-- Looking for log - not found
-- Looking for exp
-- Looking for exp - not found
Run Code Online (Sandbox Code Playgroud)

如果我深入挖掘,运行cmake --trace,我会看到以下几行:

.../tutorial/src/CMakeLists.txt(19):  include( CheckFunctionExists )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(32):  macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE )
.../tutorial/src/CMakeLists.txt(20):  check_function_exists(log HAVE_LOG )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33):  if(HAVE_LOG MATCHES ^HAVE_LOG$ )
.../tutorial/src/CMakeLists.txt(21):  check_function_exists(exp HAVE_EXP )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33):  if(HAVE_EXP MATCHES …
Run Code Online (Sandbox Code Playgroud)

c++ cmake

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

SFINAE 模板的 CUDA 10.1 编译错误

CUDA 10.1
g++ 7.3

为了单元测试套件的目的,我需要大量可重复的数据(超过可以硬编码的数据)。我提出了这个“生成器”范例,其想法是它可以用来向任意容器填充数据。

现在我需要扩展生成器来填充多值容器(float2int2thrust::complex)。我的解决方案是使用 SFINAE 根据是否可以从单个值构造函数或需要一对值来有条件地定义函数。

下面的代码使用 GCC ( -std=c++1z) 可以正常编译,但使用 nvcc ( -std=c++14)则失败

#include <random>
#include <type_traits>

template <typename T>
class RandomGenerator
{
public:
    RandomGenerator(T min, T max, unsigned seed = 42);

    // Generate the next element in the sequence. This requires keeping all the necessary state
    // to advance
    T operator()();

    // fill a container if it is scalar
    template<typename Container>
    typename std::enable_if_t<std::is_constructible_v<typename Container::value_type, T>>
    fill( Container& c …
Run Code Online (Sandbox Code Playgroud)

cuda c++11

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