c%2b%2b17's questions - English 1answer

1.975 c%2b%2b17 questions.

So i have been doing some googling about and searching on this site, but i'm struggling to find an answer to the following code and hoping that someone with more knowledge of list initializer can help ...

Is it possible to deduce template value (not type) for a c++17 function? The function foo: template<int I> int foo() { return (I); } Can be called via: foo<5>(); And will return 5....

C++17 ยง10.1.5/1 states: The constexpr specifier shall be applied only to the definition of a variable or variable template or the declaration of a function or function template. A function or ...

I'm working on a variadic class template but I cannot use it with a new expression without specifying the template arguments (I don't want to). I reduced the problem to the following code sample: ...

Some Background: I'm working on putting together a templated class which, as part of template specialization, deduces a type to use for one of its members. This data member needs to support being ...

I would like to know if there is any difference the following two types of std::vector initialization in C++11 and later. std::vector<int> v1 {1, 2, 3, 4, 5}; std::vector<int> v2 = {1, 2, ...

Are there any advantages for std::string_view over char* other than the std::string_view methods? Are there any reasons to re-factor char* into string_view if none of string_view's methods would be ...

Here's a small snippet of code: template<void(*)()> struct s{}; int main() { s<+[]{}> t; } I'm trying to take the pointer to the function of the lambda. It compiles in clang but GCC ...

I am playing around with std::tuples in various contexts and came across some things that are working, but I am unsure whether they have a performance penalty. In C++17 an init statement has been ...

This std::visit example is not understood by Eclipse CDT yet but it compiles fine with a C++17 compiler. I mean these lines: template<class... Ts> struct overloaded : Ts... { using Ts::...

With this trivial example, I get a compilation error: #include <unordered_map> int main() { std::unordered_map<int, int> a, b; a.merge(b); } Error: $ clang++ -std=c++17 merge....

Update: I have filed a bug report at visualstudio.com. So I'm starting to get into C++'s templates and I ran into this issue when trying to prevent a template class from being compiled using ...

In c++ what's the difference between stem() and filename() Both seem to do the same thing, except stem() returns "" if there is no file, but an empty folder? I would prefer to use filename(), is ...

Template argument deduction appears to be broken in Clang 6 for temporary objects. g++ 8.1.0 compiles and runs the example correctly. Clang 6.0.0 and 6.0.2 both error at the indicated line with this ...

I wonder what is the difference between this code that works : #include <type_traits> #include <iostream> template<typename T> using is_ref = std::enable_if_t<std::...

Consider these code snippets: Version (1) void q() {} class B { void f() noexcept(noexcept(q())) {q(); } decltype(&B::f) f2; }; Version (2) void q() {} class B { void f() noexcept(true) ...

I go through the book C++ template unique quide and I try to understand how the deduction guides for std::array works. Regarding the definition of the standard the following is the declaration ...

In C++20, under the proposal Familiar template syntax for generic lambdas, the following code correctly deduces type T: auto lamTest = []<typename T>(std::initializer_list<T> const & ...

Consider the following simple move-only class: struct bar { constexpr bar() = default; bar(bar const&) = delete; bar(bar&&) = default; bar& operator=(bar const&...

I generate a large number of class instances and store them in a std::unordered_set. I have defined a hash function and an equality relation, and so far everything works as it should - I insert 10000 ...

What is the time complexity of std::map::insert or std::map::assign with hint provided in the case that the element already exists in the map? CPP-Reference says that it's the same as emplace_hint, ...

I'm using the clang that comes bundled with Xcode 9.3, and I'm trying to understand whether the following result is an intentional part of C++17 changes: #include <iostream> template<...

I try to find a way in C++17 to shorten following function calls: GetCurrentContext()->GetEntityManager()->CreateEntity(); maybe to something like: EM()->CreateEntity(); I tried a ...

Since C++17 we have std::variant, which is a discriminated union. Now we have a typesafe way to hold many alternatves. But what are the real use cases for this wrapper type? I can think of a few ...

Please see code snippets (implementation of matrix multiplication) below.Is it possible to simplify them using nested pack expansion to have something like {{((a[r][k] * b[k][c]) + ...)...}...}? #...

I am using std::ptr_fun as follows: static inline std::string &ltrim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::...

I have a Register function which takes a std::function<void(const uint8_t* data, size_t len)> as a parameter. I want to use the member function of an object as the target. I found this ...

I'm trying to use boost::hana to create a constexpr lookup table that gets quite big (up to 32768 elements). This is my code: #include <boost/hana.hpp> #include <boost/hana/assert.hpp> ...

I want to use if constexpr instead of tag dispatching, but I am not sure how to use it. Example code below. template<typename T> struct MyTag { static const int Supported = 0; }; template&...

I've been meddling with signal processing on my free time, and I'm writing my own DSP library as a learning exercise. I've written a function which computes the discrete fourier transform of a vector. ...

I am trying to use the result of a constexpr function as a template parameter and cannot figure out how to get it to work. I have the following code: #include <functional> #include <...

I want to write a function that accepts a variable number of string literals. If I was writing in C, I would have to write something like: void foo(const char *first, ...); and then the call would ...

Consider the following code. If my understanding of if constexpr is correct, the else branch should not be compiled so the z() should not be considered an error. #include <type_traits> struct ...

First things first: I'm using C++17 and would be fine with using Boost::Hana, since I'm using it anyway in my code. I'm trying to emulate explicit class template instantiation (i.e., all members' ...

Say I want all numbers from 23 to 57 be in a vector. I can do this: vector<int> result; for (int i = 23; i <= 57; ++i) { result.push_back(i); } But this is a 5 line solution for a ...

I tried to write code like this: #include <string> #include <vector> #include <utility> using namespace std::string_literals; int main(){ std::vector v{1,2,3}; std::pair p{...

#include <iostream> #include <type_traits> struct A { double x; }; int main() { const A && a1 = A(); std::cout << std::is_same_v<decltype((a1.x)), const double&...

Say for example I have a long statement like cout << findCurrent() << "," << findLowest() << "," << findHighest() << "," << findThird()<<"\n"; would ...

Recently i was making a small toolkit of functions. Here is the code of header and source file Header: #pragma once #include <optional> #include <functional> #include <chrono> ...

Some of the new features that have been added to the recent ISO C++ standards were originally part of boost. This naturally raises the question of guidelines for writing portable code. Is there a ...

I'm trying to create a map of Key-Task pairs at compilation time. The key is a sequential number which should also be used as a template parameter inside of the mapped Task types. What I learned is ...

Sorry for the vague title, I don't understand the problem well enough to even describe it properly. I just don't understand why the last line of my main() fails. A moderate amount of nested template ...

According to http://en.cppreference.com/w/cpp/types/size_t , the type size_t is defined in many header files: cstddef, cstdio, cstdlib, etc. While writing my own code which header file should I ...

How to preserve the default constructor in the derived class, without adding Derived() = default; in the derived class? struct Base { Base() = default; }; struct Derived : Base { using Base::...

I'm using Windows 10, Visual Studio 2017 v15.7.1 with /std:c++latest /permissive- This simple code with structured bindings won't compile: auto [a, b] = func1(x, y, z); // auto func1() -> std::...

Related tags

Hot questions

Language

Popular Tags