c++17

Function template parameters failing to convert type during compilation

瘦欲@ 提交于 2020-01-06 11:20:14
问题 While trying to use a function template that calls a class's specialized static function template it is failing to convert its parameter from the template parameter list. Here is the function that I'm calling in main: template<class Engine, typename Type, template<typename = Type> class Distribution, class... DistParams> Type randomGenerator( RE::SeedType seedType, std::size_t seedValue, std::initializer_list<std::size_t> list, DistParams... params ) { static Type retVal = 0; static Engine

Avoiding ambiguity in overload resolution

青春壹個敷衍的年華 提交于 2020-01-06 09:06:50
问题 This is a follow up to this question so if you need to see the Register class please refer to that question. Now based on the supplied answer I have written a function to do just that. I have 2 versions of the function one that will store the results back into the original and one that will return a copy. Here are my functions: template<std::uint64_t N> void reverseBitOrder( Register<N>& reg ) { auto str = reg.register_.to_string(); std::reverse(str.begin(), str.end()); auto x = vpc::Byte(str

Avoiding ambiguity in overload resolution

怎甘沉沦 提交于 2020-01-06 09:06:31
问题 This is a follow up to this question so if you need to see the Register class please refer to that question. Now based on the supplied answer I have written a function to do just that. I have 2 versions of the function one that will store the results back into the original and one that will return a copy. Here are my functions: template<std::uint64_t N> void reverseBitOrder( Register<N>& reg ) { auto str = reg.register_.to_string(); std::reverse(str.begin(), str.end()); auto x = vpc::Byte(str

How to avoid code duplicate const and non-const collection processing with lambda

为君一笑 提交于 2020-01-06 05:59:08
问题 The answer here does not work for this pattern in C++17: template <typename Processor> void Collection::ProcessCollection(Processor & processor) const { for( int idx = -1 ; ++idx < m_LocalLimit ; ) { if ( m_Data[ idx ] ) { processor( m_Data[idx] ); } } const int overflowSize = OverflowSize(); for( int idx = -1 ; ++idx < overflowSize ; ) { processor( (*m_Overflow)[ idx ] ); } } // How to avoid this repetition for non-const version? template <typename Processor> void Collection:

How to stop template recursion while using parameter deduction?

核能气质少年 提交于 2020-01-06 04:37:08
问题 This code task a const char[] and finds where is the last slash: #include <array> #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) template< int PathIndex, int PathLength > constexpr const int findlastslash(const char (&path)[PathLength]) { constexpr const int end = PathLength - PathIndex; return (PathIndex >= 0 && path[end] != '/' && path[end] != '\\') ? findlastslash< PathIndex - 1, PathLength >( path ) : ( end + 1 ); } template< int PathLength > constexpr const int

C++17 using std::variant to represent DOM

时光总嘲笑我的痴心妄想 提交于 2020-01-06 04:32:24
问题 I'm trying to learn how to use std::variant from C++17. As an example started using it, to represent the DOM. Though this is still work in progress: I wanted to get expert opinion on the usage of std::variant also some inputs on the compiler support. I've the DOM representation code (Godbolt's Compiler Explorer link) and it seems to compile fine with Clang trunk. However, I see that the same code does not compile with GCC 8.0.0 20171009. I would like to understand what is the reason for this

template multiple variadic inheritance with variadic argument types

十年热恋 提交于 2020-01-06 04:23:06
问题 I need to inherit multiple times the following class, taking variadic arguments as template parameters. template <class SignalDispatcherClass, class ... ArgTypes> class ISignalMap { //private public: void RegisterSlot(SignalAddress pSignalFunc, ISlotInvoker<ArgTypes...>* pSlotInvoker) { //implementation } }; So far I can expand a parameter pack and get multiple class specializations, but with functions taking only one argument. template <class SignalDispatcherClass, class ... ArgTypes> class

Is there a way of making a lock-free “counter” random access iterator in C++?

末鹿安然 提交于 2020-01-05 08:32:53
问题 I'm experimenting with the execution policies on a toy problem of evaluating a polynomial at a certain point, given its coefficients and the point of evaluation (x). Here's my implementation: class counter: public std::iterator< std::random_access_iterator_tag, // iterator_category size_t, // value_type size_t, // difference_type const size_t*, // pointer size_t // reference >{ size_t num = 0; public: explicit counter(size_t _num) : num(_num) {} counter& operator++() {num += 1; return *this;}

Is there a way of making a lock-free “counter” random access iterator in C++?

瘦欲@ 提交于 2020-01-05 08:32:04
问题 I'm experimenting with the execution policies on a toy problem of evaluating a polynomial at a certain point, given its coefficients and the point of evaluation (x). Here's my implementation: class counter: public std::iterator< std::random_access_iterator_tag, // iterator_category size_t, // value_type size_t, // difference_type const size_t*, // pointer size_t // reference >{ size_t num = 0; public: explicit counter(size_t _num) : num(_num) {} counter& operator++() {num += 1; return *this;}

Declare friend function which is defined in an earlier friend definition

痞子三分冷 提交于 2020-01-05 04:58:18
问题 The following defines a friend function in the global namespace, the declares that same function as a friend class Cls { friend void func(int) { } friend void ::func(int); }; clang accepts this, while gcc rejects with so.cpp:3:17: error: ‘void func(int)’ has not been declared within ‘::’ friend void ::func(int); ^~ so.cpp:2:17: note: only here as a ‘friend’ friend void func(int) { } ^~~~ This looks like it should be fine to me, its defining a function in the global namespace isn't it? The gcc