c++17

Abbreviate argument to member function expecting introduced type (enum class)

大城市里の小女人 提交于 2019-12-11 15:28:37
问题 TL;DR Is there a Shorter syntax for the enum class type argument to a member function ( field_inst.write(decltype(field_inst)::Type::cpr1_4096); ) in the following code? namespace Hal { // complex template definition `Bit_Field` template< class Tregister, typename Tregister::Data Toffset, typename Tregister::Data Tmask, class Tfield_type, class Tmutability_policy = typename Tregister::Mutability_Policy > struct Bit_Field : Tregister { using Type = Tfield_type; static Field read() { // ...

C++ Alternating between two variables at compile time

◇◆丶佛笑我妖孽 提交于 2019-12-11 15:18:16
问题 Suppose you have a class that operates on a vector: class Foo{ public: Foo() { m_dynamic_data.push_back(5); std::cout << m_dynamic_data[0] << std::endl; } private: std::vector<int> m_dynamic_data; }; In my case this class is huge with 2500 additional lines of code. This class behaves dynamic (hence std::vector ). But I would also like to provide a "static" implementation (using std::array ). So std::size_t N is added, which now should control when to use which attribute. template<std::size_t

Resolving a compiler error due to an invariant member with a possible deleted default constructor

青春壹個敷衍的年華 提交于 2019-12-11 14:55:47
问题 I have asked a series of questions that all relate to the same source code in this order: experimenting-with-unions-and-bitfields-within-a-structures-and-templates trying-to-flip-the-order-of-bits-in-stdbitset avoiding-ambiguity-in-overload-resolution I've also asked these series of questions over at Code Review that are also related. emulating-virtual-registers-by-experimenting-with-unions-bitfields-structs-and-template-specialization emulating-virtual-registers-part-2 This should give you

C++17 construct array in stack using chosen constructor (same constructor parameter values for each array entry)

痞子三分冷 提交于 2019-12-11 14:31:31
问题 Is it a way in c++17 to construct an array in stack using another constructor than the default constructor. This is a special case when each array value is constructed with the same constructor parameters. I need to use a basic stack located array (not a vector or an array of pointers or something else). This code illustrate what I would like to do : #include <iostream> using namespace std; struct A { A() { printf("A() called\n"); } A(int i, int j) { printf("A(%d, %d) called\n", i, j); } };

How to use <execution> library in c++17

淺唱寂寞╮ 提交于 2019-12-11 14:29:52
问题 Learning how to use the execution libraries in c++17. I am using Linux, but have also tried on my Mac. I get this error: fatal error: 'execution' file not found when i compile in both OS's. I would rather stick with linux where i type: g++ -g -std=c++17 ModuleDevelopmentStage13.cc -lboost_system -lboost_thread -pthread Perhaps I need to add some more libraries in the -l.... arguments here. I am new to c++ and not sure where to find out which ones to add? I have installed the LLVM and tried a

front and back Proposal for iterators Library

ぃ、小莉子 提交于 2019-12-11 13:56:09
问题 In C++17 the iterator library received size, empty, and data allowing statically constructed arrays to behave like containers. But I don't see a front or back function in the iterator library, which was added to the other containers in C++14: http://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search=front&button= Is this something that has been proposed? 回答1: N4017 originally proposed front / back . The Library Evolution Working Group voted to remove front / back : Do we want

Can I use the iterator Libraries' Access Functions on Nonstandard Containers?

一笑奈何 提交于 2019-12-11 11:43:30
问题 The iterator library has been introducing a lot of access functions over the course of C++11, C++14, and C++17: begin / end cbegin / cend crbegin / crend data empty rbegin / rend size Can I use these on any container, even nonstandard containers (provided they supply an accessible corresponding method?) For example given a QVector foo can I do this: const auto bar = begin(foo); 回答1: The declarations for std::begin are as follow (from §24.7): template <class C> auto begin(C& c) -> decltype(c

Omit angle brackets when template has default parameters

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:47:30
问题 Suppose we have a class template with default template parameter: template <typename T = int> class Foo {}; We can omit angle brackets when creating a variable inside a function: int main() { Foo a; // gets properly deduced as Foo<int> } But we can't do that for member variables: struct S { Foo a; // Deduce Foo<int> }; We can't have derivative types such as this: Foo* ptr; // Foo<int>* Foo& ref; // Foo<int>& int Foo::* mem_ptr; // int Foo<int>::* std::function<Foo(const Foo&)> fn; // std:

Can I call optional::emplace as a member initializer?

走远了吗. 提交于 2019-12-11 10:44:51
问题 I'm trying to add a new constructor an existing class and wondering if I can somehow do an emplace initialization of an optional and then use that value in the initializer for another member value. For example: class sample { my_type sc; optional<opt_type> run; sample() : sc( gen_default() ) { } enum ctor_alt { ctor_alt }; sample( ctor_alt ) : emplace( run, ctor_arg ), /* Possible somehow? */ sc( run.field ) { } My primary motivation is that I don't want to alter the type of my_type . There

Class Template Argument Deduction in member variables

倖福魔咒の 提交于 2019-12-11 10:40:36
问题 Expanded version here. We can create objects of class templates that have default template parameters without typing angle brackets: int main() { std::less a; } But we can't do that for member variables: struct S { std::less a; // I want only type std::less<void> here }; It looks like the first case works due to CTAD but why can't compiler deduce std::less<void> in the second case? Maybe we shouldn't apply CTAD there but provide different mechanism. Is this considered a bug in the standard?