c++17 Questions
0
C++17 allows scoped enums to be initialized with integers as long as it's not narrowing, e.g.
#include <cstdint>
enum class e16 : uint16_t { x16, y16 };
enum class e32 : uint32_t { x32, y32 }...
Andria asked 23/10 at 23:35
1
I have a source file with a large byte array representing an image.
Below an example (in reality it can be any random data):
const uint8_t image_test_image[] ={
0x00, 0x01, 0x02, 0x03, 0x04, 0x05,...
4
c++17 provides if constexpr, in which:
the value of condition must be a contextually converted constant expression of type bool. If the value is true, then statement-false is discarded (if prese...
Cymbal asked 21/2, 2018 at 18:34
3
Solved
I want to get a range of elements from a std::vector<MyClass> and store them as const-ref, because I only want to read but not modify them.
#include <iostream>
#include <vector>
...
2
Solved
I'm dealing with a vendor-provided C-library (let's call it foo), that offers a multitude of API-calls. All of these functions take a (pre-initialized) handle (of type FOOHandle) and return 0 on su...
1
For a better understanding of this question, here is the code:
// code 1
#include <iostream>
#include <thread>
struct tls_test {
tls_test()
{ std::cout << "tls_test ctor\n...
Thanasi asked 25/6, 2023 at 2:39
2
I am trying to ignore the unused parameter warning using the new c++17 attribute [[maybe_unused]], as below.
int main([[maybe_unused]] int argc, char** argv)
{
//...
}
But I still get warning: ...
8
Solved
Task Description
interval_map<K,V> is a data structure that efficiently associates intervals of keys of type K with values of type V. Your task is to implement the assign member function...
3
Solved
I have a parameter pack given in a variadic class template and want to extract the first type.
Currently I do this, which works fine but is somehow cumbersome. Is it possible to do the same thing s...
Throw asked 8/8, 2017 at 21:44
4
Solved
Consider the following program:
#include <tuple>
#include <vector>
#include <iostream>
#include <type_traits>
template <class T>
struct ordered {};
template <cla...
Ahem asked 10/2, 2018 at 18:9
4
Solved
Maybe I missed something, but I can't find any hints: is there a constexpr ternary operator in C++17 equivalent to constexpr-if?
template<typename Mode>
class BusAddress {
public:
explicit ...
Lette asked 7/12, 2016 at 7:44
1
Solved
Having class X, the following object initialization:
new (ptr) X(X());
requires an accessible destructor even since C++17. Why is that, when the object is initialized by the default constructor di...
Serenata asked 15/7 at 13:9
4
Solved
I'm not able to provide a std::string_view to std::istringstream's constructor. The following code doesn't compile (C++17 enabled using Clang v8):
std::string_view val = "Hello";
std::istringstrea...
3
Solved
I'm starting a project using C++, which I haven't used before outside of a handful of school projects - nowhere near the scope of what I'm tackling now.
My goal is to try my best to follow the C++...
Sperling asked 4/2, 2019 at 17:11
3
Solved
In the question Idiom for initializing an std::array using a generator function taking the index?,which basically asks how one can initialize an array of an arbitrary type which is not necessarily ...
Gribble asked 26/6 at 14:23
2
Suppose I have a function T foo(size_t i). What would be an elegant and succinct way of constructing an object arr, of type std::array<T, N>, so that we have arr[i] == foo(i)?
If possible, I ...
Amagasaki asked 26/6 at 12:28
5
Solved
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...
Alaynaalayne asked 28/2, 2019 at 17:41
20
Solved
I doubt it can be done portably, but are there any solutions out there? I think it could be done by creating an alternate stack and reseting SP,BP, and IP on function entry, and having yield save I...
5
I have a enum class, for example:
enum class State{
S1,
S2,
S3,
S4
};
And whenever I make a switch/case statement that might use this class, I would like to avoid using a "default" ...
Centrosphere asked 13/7, 2021 at 9:18
2
Solved
I'd like to use std::is_invocable, but it is available only since C++17, and we are using C++11 Standard.
Is there any way to emulate the functionality using C++11?
Convex asked 5/7, 2018 at 9:36
2
Solved
I am playing around with fold expression in c++17 with the latest clang++. I tried to implement the less operator for an array using this which I want to use for fixed size strings.
Here is where ...
Luminescence asked 7/7, 2015 at 16:29
4
I need to alias std::get function in order to improve readability in my code.
Unfortunately I got a compile-time error get<0> in namespace ‘std’ does not name a type. using is equivalent to ...
5
Solved
I try next code with three compilers (msvc2017, gcc8.2, clang7.0) and msvc2017 works all the way, but gcc and clang not. I want to understand what is wrong with my code, and why compiler can't comp...
8
Solved
Is there a standard way to get the types of a function's arguments and pass around these types as a template parameter pack? I know that this is possible in C++ because it has been done before.
I ...
Catamaran asked 13/2, 2015 at 21:45
5
Solved
I want to raise a compile time error when non of the constexpr if conditions is true eg:
if constexpr(condition1){
...
} else if constexpr (condition2) {
....
} else if constexpr (condition3) {
...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.