当移动std::unique_ptr
到拉姆达,这是不可能的调用reset()
就可以了,因为它似乎是常量,则:
error C2662: void std::unique_ptr<int,std::default_delete<_Ty>>::reset(int *) noexcept': cannot convert 'this' pointer from 'const std::unique_ptr<int,std::default_delete<_Ty>>' to 'std::unique_ptr<int,std::default_delete<_Ty>> &
Run Code Online (Sandbox Code Playgroud)
#include <memory>
int main()
{
auto u = std::unique_ptr<int>();
auto l = [v = std::move(u)]{
v.reset(); // this doesn't compile
};
}
Run Code Online (Sandbox Code Playgroud)
std::unique_ptr
允许reset()
在lambda(使用C ++ 17或更高版本)中调用的另一种方式捕获?从升级当我遇到一个问题#include <experimental/filesystem>
来#include <filesystem>
.似乎该std::filesystem::path::wstring
方法没有返回与中相同的字符串experimental::filesystem
.我编写了以下小测试程序,其中包含输出结果.
#include <iostream>
#include <filesystem>
#include <experimental/filesystem>
namespace fs = std::filesystem;
namespace ex = std::experimental::filesystem;
using namespace std;
int main()
{
fs::path p1{ L"C:\\temp/foo" };
wcout << "std::filesystem Native: " << p1.wstring() << " Generic: " << p1.generic_wstring() << endl;
ex::path p2{ L"C:\\temp/foo" };
wcout << "std::experimental::filesystem Native: " << p2.wstring() << " Generic: " << p2.generic_wstring() << endl;
}
/* Output:
std::filesystem Native: C:\temp/foo Generic: C:/temp/foo
std::experimental::filesystem Native: C:\temp\foo …
Run Code Online (Sandbox Code Playgroud) 我有一个包含路径的字符串
str = "/example/path/with/different/trailing/delimiter\"
Run Code Online (Sandbox Code Playgroud)
我要修剪开头和结尾/
和\
。Python 3的最佳做法是什么?
目前我正在使用
trimmedPath = str.strip("/\\")
# trimmedPath is "example/path/with/different/trailing/delimiter" as desired
Run Code Online (Sandbox Code Playgroud)
两个问题:
文件路径作为字符串传递.如何将此字符串转换为std :: filesystem :: path?例:
#include <filesystem>
std::string inputPath = "a/custom/path.ext";
const std::filesystem::path path = inputPath; // Is this assignment safe?
Run Code Online (Sandbox Code Playgroud) 尝试使用OpenMP 3中的功能
#pragma omp parallel for collapse(2)
Run Code Online (Sandbox Code Playgroud)
在Visual Studio 2017中; 我越来越error c3005: 'collapse' unexpected token encountered on openmp 'parallel for' directive
Visual Studio 2017似乎只支持OpenMP2.在一个支持OpenMP4.5的请求中,来自VS团队的说法
我们目前没有计划.
另一个答案说
幸运的是,clang-cl已成为OpenMP 4支持的可行替代方案.在最坏的情况下,您仍然可以启用/ fallback选项.
如何在Visual Studio 2017中使用clang-cl以及什么是后备选项?
使用C++,是否可以递归地将文件和目录从一个路径复制到另一个路径
考虑以下文件系统
src/fileInRoot
src/sub_directory/
src/sub_directory/fileInSubdir
Run Code Online (Sandbox Code Playgroud)
我要复制
从src
另一个目录target
.
我创建了一个新问题,因为我发现的问题是特定于平台的,不包括过滤:
我已经看到我的Visual C++项目具有以下声明,这些声明使用COMMAS而不是DOTS用于版本:
#define FILEVER 11,0,2,0
#define PRODUCTVER 11,0,2,0
#define STRFILEVER "11, 0, 2, 0\0"
#define STRPRODUCTVER "11, 0, 2, 0\0"
Run Code Online (Sandbox Code Playgroud)
这里的MS文章也有逗号相同的值(实际上上述声明基于该文章).我们为什么在这里使用COMMAS?当我打开编译的文件属性时,我看到FileVersion为11.0.2.0但是ProductVersion为11,0,2,0 - 我的QA朋友说它是一个bug :).我缺少一些标准或者一些内部机制吗?
我想从另一个字符串变量创建const字符串.例如,接下来的两个代码片段无法编译
1)
string str = "111";
const string str2 = str;
Run Code Online (Sandbox Code Playgroud)
2)
string str = "111";
const string str2 = new string(str.ToCharArray());
Run Code Online (Sandbox Code Playgroud)
结果如何
Error: The expression being assigned to 'str2' must be constant
Run Code Online (Sandbox Code Playgroud)
有没有办法从字符串变量创建一个const字符串?
我正在使用exprtk创建一个表达式,使用不断变化的变量.
每次更改变量的值时,是否必须重置并重新编译exprtk::expression
使用更新exprtk::symbol_table
?
或者更新的值是否由现有的编译表达式直接评估?
#include <iostream>
#include <string>
#include "exprtk.hpp"
int main() {
std::string expression_string = "y := x + 1";
int x = 1;
exprtk::symbol_table<int> symbol_table;
symbol_table.add_variable("x", x);
exprtk::expression<int> expression;
expression.register_symbol_table(symbol_table);
exprtk::parser<int> parser;
if (!parser.compile(expression_string, expression))
{
std::cout << "Compilation error." << std::endl;
return 1;
}
expression.value(); // 1 + 1
x = 2;
// Do I have to create a new symbol_table, expression and parse again?
// Or does the expression evaluate the …
Run Code Online (Sandbox Code Playgroud) 由于在 C++17 中std::filesystem::file_time_type
使用了一个普通时钟,有没有办法检索file_time_type
C++17**的实际时钟类型?
目标是将时间转换为std::chrono::system_clock
在流中使用它。
** 在 C++20 中,file_time_type
将使用std::chrono::file_clock
,它具有operator<<
并且可以使用std::chrono::clock_cast
.
c++ ×7
c++17 ×3
c# ×1
c++-chrono ×1
c++11 ×1
capture-list ×1
clang-cl ×1
const ×1
exprtk ×1
filesystems ×1
lambda ×1
openmp ×1
python ×1
python-3.x ×1
string ×1
unique-ptr ×1
versioning ×1
visual-c++ ×1