c++17

Can C++17 be used together with CUDA using clang?

烂漫一生 提交于 2020-12-02 05:58:05
问题 As far as using nvcc , one needs to use the corresponding gcc (currently max. 5.4 I believe) in conjunction. This of course somewhat prevents one from using C++17 on the host side. Since C++17 can be compiled using clang 5 and upwards (see here), and one can compile cuda code as well (see here), is it possible to use both C++17 and CUDA at the same time (or can there be problems, e.g. with the CUDA runtime)? 回答1: Yes, as you already guessed the CUDA clang frontend is indeed ahead in C++

How do c++ compilers find an extern variable?

試著忘記壹切 提交于 2020-12-01 09:10:16
问题 I compile this program by g++ and clang++. There has a difference: g++ prints 1, but clang++ prints 2. It seems that g++: the extern varible is defined in the shortest scope. clang++: the extern varible is defined in the shortest global scope. Does C++ spec has any specification about that? main.cpp #include <iostream> static int i; static int *p = &i; int main() { int i; { extern int i; i = 1; *p = 2; std::cout << i << std::endl; } } other.cpp int i; version: g++: 7.4.0/ clang++:10.0.0

How to restore auto_ptr in Visual Studio C++17

隐身守侯 提交于 2020-11-30 11:58:24
问题 This blog page mentions that Visual Studio removes some std features: https://blogs.msdn.microsoft.com/vcblog/2017/12/08/c17-feature-removals-and-deprecations/ I have a project that consumes some C++ libraries that now use C++17 features. The project also consumes a third party library websocketpp (https://github.com/zaphoyd/websocketpp) that still uses some now removed features. eg auto_ptr and binary_function. I'm getting compiler errors that they are not a member of 'std'. The blog above

How can my code do one thing at compile-time, but another thing at run-time?

陌路散爱 提交于 2020-11-28 08:05:20
问题 I'm implementing a constexpr int foo(); function. In the body of foo() , I want to do something different (and possibly return something different) at compile time and something different at run-time. With C++20, I can use std::is_constant_evaluated: constexpr int foo() { return std::is_constant_evaluated() ? 123 : 456 }; but what if I'm using C++17 (or earlier) - what can I do with the same effect? Note: Compiler-specific solutions are acceptable (though less desirable). 回答1: Note: Compiler

How can my code do one thing at compile-time, but another thing at run-time?

北城余情 提交于 2020-11-28 08:04:44
问题 I'm implementing a constexpr int foo(); function. In the body of foo() , I want to do something different (and possibly return something different) at compile time and something different at run-time. With C++20, I can use std::is_constant_evaluated: constexpr int foo() { return std::is_constant_evaluated() ? 123 : 456 }; but what if I'm using C++17 (or earlier) - what can I do with the same effect? Note: Compiler-specific solutions are acceptable (though less desirable). 回答1: Note: Compiler

How can my code do one thing at compile-time, but another thing at run-time?

我是研究僧i 提交于 2020-11-28 07:58:05
问题 I'm implementing a constexpr int foo(); function. In the body of foo() , I want to do something different (and possibly return something different) at compile time and something different at run-time. With C++20, I can use std::is_constant_evaluated: constexpr int foo() { return std::is_constant_evaluated() ? 123 : 456 }; but what if I'm using C++17 (or earlier) - what can I do with the same effect? Note: Compiler-specific solutions are acceptable (though less desirable). 回答1: Note: Compiler

Return std::tuple and move semantics / copy elision

天大地大妈咪最大 提交于 2020-11-24 16:35:17
问题 I have the following factory function: auto factory() -> std::tuple<bool, std::vector<int>> { std::vector<int> vec; vec.push_back(1); vec.push_back(2); return { true, vec }; } auto [b, vec] = factory(); In the return statement is vec considered an xvalue or prvalue and therefore moved or copy elided? My guess is no, because the compiler, when list-initializing the std::tuple in the return statement, still doesn't know that vec is going to be destroyed. So maybe an explicit std::move is