c++17

Multiple parameter packs in a single function?

时光毁灭记忆、已成空白 提交于 2021-01-27 07:31:55
问题 I'm trying to create a function that takes two parameter packs of objects. There are two templated base classes and I'd like to pass instances of derived classes to this function. Consider this example. template <int N> struct First {}; template <int N> struct Second {}; // there are a few of these struct FirstImpl : First<5> {}; struct SecondImpl : Second<7> {}; template <int... firstInts, int... secondInts> void function(float f, First<firstInts> &... first, Second<secondInts> &... second)

Multiple parameter packs in a single function?

て烟熏妆下的殇ゞ 提交于 2021-01-27 07:31:43
问题 I'm trying to create a function that takes two parameter packs of objects. There are two templated base classes and I'd like to pass instances of derived classes to this function. Consider this example. template <int N> struct First {}; template <int N> struct Second {}; // there are a few of these struct FirstImpl : First<5> {}; struct SecondImpl : Second<7> {}; template <int... firstInts, int... secondInts> void function(float f, First<firstInts> &... first, Second<secondInts> &... second)

C++: Can't propagate polymorphic_allocator with scoped_allocator_adaptor

荒凉一梦 提交于 2021-01-27 05:24:39
问题 I have a vector<vector<int>> and want the entire memory (i.e., of both the outer and the inner vector) to be taken from a memory_resource . Here is a stripped down example, first the boring part: #include <boost/container/pmr/memory_resource.hpp> #include <boost/container/scoped_allocator.hpp> #include <boost/container/pmr/polymorphic_allocator.hpp> #include <iostream> #include <string> #include <vector> // Sample memory resource that prints debug information class MemoryResource : public

Why is implicit conversion not applied to templated function parameter?

佐手、 提交于 2021-01-27 05:02:51
问题 I'm having an issue with some template stuff that I've narrowed down to the following example (C++17): template <typename T> struct item { operator item<const T> () const { return item<const T>(); } }; void conversionToConstRefWorks (const item<const int> &) { } template <typename T> void butNotWhenTemplated (const item<const T> &) { } int main () { item<int> i; item<const int> ci; // these all compile fine: conversionToConstRefWorks(ci); conversionToConstRefWorks(i); butNotWhenTemplated(ci);

Why is implicit conversion not applied to templated function parameter?

与世无争的帅哥 提交于 2021-01-27 05:00:13
问题 I'm having an issue with some template stuff that I've narrowed down to the following example (C++17): template <typename T> struct item { operator item<const T> () const { return item<const T>(); } }; void conversionToConstRefWorks (const item<const int> &) { } template <typename T> void butNotWhenTemplated (const item<const T> &) { } int main () { item<int> i; item<const int> ci; // these all compile fine: conversionToConstRefWorks(ci); conversionToConstRefWorks(i); butNotWhenTemplated(ci);

How to let a variable be dependent on other variables inside a class?

天涯浪子 提交于 2021-01-27 04:48:23
问题 What is wrong with the variable international_standard_book_number ? How can I make it that it changes, whenever isbn_field_i changes? #include <iostream> #include <string> class ISBN { private: unsigned int isbn_field_1 = 0; unsigned int isbn_field_2 = 0; unsigned int isbn_field_3 = 0; char digit_or_letter = 'a'; std::string international_standard_book_number = std::to_string(isbn_field_1) + "-" + std::to_string(isbn_field_2) + "-" + std::to_string(isbn_field_3) + "-" + digit_or_letter;

How to flatten heterogeneous lists (aka tuples of tuples of …)

牧云@^-^@ 提交于 2021-01-27 04:07:10
问题 I am attempting to employ C++17 fold expressions and the C++14 indices trick to flatten an arbitrary input consisting of tuples and non-tuples. The expected result should at least conform to these requirements: constexpr auto bare = 42; constexpr auto single = std::tuple{bare}; constexpr auto nested_simple = std::tuple{single}; constexpr auto multiple = std::tuple{bare, bare}; constexpr auto nested_multiple = std::tuple{multiple}; constexpr auto multiply_nested = std::tuple{multiple, multiple

How to flatten heterogeneous lists (aka tuples of tuples of …)

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-27 04:06:51
问题 I am attempting to employ C++17 fold expressions and the C++14 indices trick to flatten an arbitrary input consisting of tuples and non-tuples. The expected result should at least conform to these requirements: constexpr auto bare = 42; constexpr auto single = std::tuple{bare}; constexpr auto nested_simple = std::tuple{single}; constexpr auto multiple = std::tuple{bare, bare}; constexpr auto nested_multiple = std::tuple{multiple}; constexpr auto multiply_nested = std::tuple{multiple, multiple

Which compilers support std::filesystem?

岁酱吖の 提交于 2021-01-27 02:55:06
问题 Thanks to C++11, after a long relationship with boost, the last component that makes me depend on it is the filesystem. std::filesystem seems to be implemented as experimental according to the link: Filesystem library Since it mimics boost::filesystem, I can easily adapt my project into std and get rid of huge boost dependency. Which compilers support it and would it matter to use it even though it is experimental since it mimics boost (since there is no time schedule for when it will be

clang c++17 std::vector over aligned types copy of elements SIGSEGV when compiled with -mavx

家住魔仙堡 提交于 2021-01-26 23:28:28
问题 According to this question I thought that in C++17 a std::vector with default allocator should handle over aligned types. However, the following code #include <iostream> #include <iterator> #include <array> #include <vector> template<typename T, size_t N, size_t Alignment> struct alignas(Alignment) AlignedArray : public std::array<T, N> { friend std::ostream& operator<<(std::ostream& o, const AlignedArray& a) { std::copy(a.cbegin(), a.cend(), std::ostream_iterator<T>(o, " ")); return o; } };