c++17

What is a fully qualified name?

坚强是说给别人听的谎言 提交于 2019-12-08 14:26:14
问题 As far as I can tell, the term fully qualified isn't mentioned in the standard (e.g.), but I can recall "hearing" it many times online. What do people mean when they say a name is fully qualified? Does this count? A::f() or only this? ::A::f() And, if it is standard, which wording have I not found? 回答1: An identifier that uses the scope resolution operator is a qualified name as per [expr.prim.id.qual]. Otherwise it is unqualified. The standard doesn't define the meaning of fully qualified ,

Defining a proxy-based OutputIterator in terms of boost::iterator_facade

风流意气都作罢 提交于 2019-12-08 14:07:19
问题 I wrote this C++17 code and expected it to work out of the box. class putc_iterator : public boost::iterator_facade< putc_iterator, void, std::output_iterator_tag > { friend class boost::iterator_core_access; struct proxy { void operator= (char ch) { putc(ch, stdout); } }; auto dereference() const { return proxy{}; } void increment() {} bool equal(const putc_iterator&) const { return false; } }; I'm trying to match the behavior of all the standard OutputIterators by setting my iterator's

CMake with MSVC Ninja gives compiler & test program error

半世苍凉 提交于 2019-12-08 13:55:36
问题 I have the following C++ build setup (using MSVC 2019 + Ninja): build.bat @echo off mkdir build_folder cd build_folder call "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.21.27702/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019

Is it possible to create a better version of `std::min` & `std::max`?

蹲街弑〆低调 提交于 2019-12-08 12:43:40
问题 With the new features of C++17, is it possible to create a better std::min and std::max ? What I mean by better: std::min/max has the problem of dangling references. std::min/max doesn't work with different types (i.e., min(short, int) needs to explicitly specify the type min<int>(...) ) I'd like to have a better implementation, which: avoids the dangling reference problem (for example, min(a, 4); works correctly) works with different types (for example, min((short)4, (int)8); compiles)

how to Enable c++17 Support in code blocks

岁酱吖の 提交于 2019-12-08 10:20:13
问题 in codeblocks There isn't a C++17 option in the Build or Compiler options, only C++14 how can i enable it in codeblocks so that both coding tools and compiler support it? 回答1: Code::Blocks is not a compiler (but some glorified source code editor, sometimes calling themselves IDEs, which runs some external compiler). You need a C++17 compiler (and once you've got one you might configure your IDE or editor to use it with the appropriate options). Try the very latest version of GCC (at least GCC

Creating std::vector of nonmovable type

泪湿孤枕 提交于 2019-12-08 07:17:31
问题 I have a std::vector named args (I don’t know the size of the vector at compile time) and a non movable type NonMoveable . I want to create a vector of the same size as args, so that it equals to {NonMovable(args[0], additional_arg), NonMovable(args[1], additional_arg), …, NonMovable(args.back(), additional_arg)} I don’t need to change the size of the vector later. How do I do that? I can’t reserve() then emplace_back() because emplace_back() requires moving (to allow reallocation which is

Template function for detecting pointer like (dereferencable) types fails for actual pointer types

拥有回忆 提交于 2019-12-08 05:38:23
问题 I am trying to write a mechanism to detect if a type is a pointer like type. By that I mean it is dereferencable through operator*() and operator->() . I have three different structs that are specialized accordingly: is_pointer_like_dereferencable which checks for operator*() is_pointer_like_arrow_dereferencable which checks for operator->() is_pointer_like which simply combines 1 & 2 I added specializations for non-templated types like int, int*, ... and for templated types like std::vector<

Template class with invalid member functions

那年仲夏 提交于 2019-12-08 03:52:45
问题 Is it legal in C++ to have instantiate class templates with classes that do not work with some of its member functions? For example: class A { public: void f() { } }; class B { }; template<typename T> class Wrapper { private: T t_; public: void call_f() { t_.f(); } }; int main() { Wrapper<A> a; Wrapper<B> b; a.call_f(); } This code compiles, and I can use b , as long as I don't try to call b.call_f() . (Also explicitly instantiating it with template class Wrapper<B>; causes a compilation

How to compile #include <experimental/any> for clang on OSX

杀马特。学长 韩版系。学妹 提交于 2019-12-08 01:57:49
问题 I am trying to get the #include <experimental/any> to compile in my C++ program on clang OSX // test.cpp #include <experimental/any> int main() { return 0; } Tried following commands/options as learnt from here clang++ -std=c++14 test.cpp -o test -std=c++1z -stdlib=libc++ clang++ -std=c++1x test.cpp -o test -std=c++1z -stdlib=libc++ clang++ -std=c++1y test.cpp -o test -std=c++1z -stdlib=libc++ clang++ -std=c++1z test.cpp -o test -std=c++1z -stdlib=libc++ But it doesn't compile & complains of

Range/Loop through N variables in [modern] C++

一笑奈何 提交于 2019-12-07 22:37:52
问题 What's a succinct way of ranging through N variables, of any type each, to perform an operation? Let's say I have variables a , b , c , d , e and want to go through all of them performing some operation. 回答1: Use Boost.Hana and generic lambdas: #include <tuple> #include <iostream> #include <boost/hana.hpp> #include <boost/hana/ext/std/tuple.hpp> struct A {}; struct B {}; struct C {}; struct D {}; struct E {}; int main() { using namespace std; using boost::hana::for_each; A a; B b; C c; D d; E