All Questions
5,504
questions
3
votes
1
answer
104
views
std::variant::operator< unexpected call to implicit bool conversion. Varies between standards
I'm seeing some unexpected behavior when using the std::variant::operator<. In the situation where the type has an implicit bool conversion operator and its less operator is not a member function (...
2
votes
2
answers
89
views
C++ Compile-Time Class With std::vector Member Variable and Use It's Data at Run-Time [duplicate]
I am trying to make a writer class, which would be used to turn data into a binary stream, at compile-time using a std::vector, and then converting it to std::array to be used at runtime. eg:
#include ...
1
vote
1
answer
84
views
consteval member function allowed?
I have this c++20/23 code:
#include <cstddef>
template <size_t N>
class Foo {
public:
consteval size_t size() noexcept { return N; }
size_t real_size() {
...
0
votes
0
answers
48
views
Does CMake support converting headers to header modules?
I've just started to learn programming in C++ and the books I use for that focus on the new module system to replace the #include method.
For make I've found Makefiles that allow to first convert the #...
0
votes
1
answer
47
views
Concept that ensures a type is defined for all indexes in a sequence
I have an indexable type trait, that can be specialized:
// Traits
template <size_t Idx, typename T>
struct nth_type;
template <size_t Idx, typename T>
using nth_type_t = typename ...
2
votes
1
answer
118
views
Is Cpp Core Guidelines Rule F19 incomplete?
Cpp Core Guideline F19 tells us
Flag a function that takes a TP&& parameter (where TP is a template type parameter name) and does anything with it other than std::forwarding it exactly once ...
4
votes
1
answer
83
views
Can I use template parameters to refer to base class member functions?
I'm trying to understand why this code doesn't compile with GCC but compiles with MSVC:
template<class TParams>
class Selector : public TParams::DataSource1, public TParams::DataSource2
{
...
0
votes
1
answer
99
views
Is it possible to have arrays of mixed C++ templates with known identical SizeOf?
As an example, I have a slab of code something like this:
template <typename T, typename MyTIO>
struct Ticklite
{
using Ticklite_Impl = T;
using Impl_InOut = MyTIO;
TickliteCadence ...
1
vote
2
answers
65
views
How to pairwise iterate over a type list and value list
I've got a typelist like
template <typename ...Types> struct type_list {};
and am looking for a way to iterate over pairs of elements from that type list and some value list from within a ...
5
votes
1
answer
99
views
On which member is no_unique_address needed and why?
Consider the following two structs whose sizes are 8 and 1 bytes respectively:
class eight {
int i;
char c;
eight(const blub&) {}
};
class one {
char s;
one(const blob&...
0
votes
2
answers
130
views
What is the correct way to check for C++20 features on G++
My understanding was the best practice is:
#if __cplusplus >= 202002L
// code
#endif
However, it does not work, even though I do compile with -std=c++20.
Also, the output of g++ -x c++ -std=c++20 -...
1
vote
1
answer
71
views
Template Argument Deduction Guides for Aliases
I want to deduce the template arguments of an aliased class template and Richard Smith says that should work in C++20.
If my alias is just a name-change, then this answer to a related question works ...
-1
votes
0
answers
70
views
What does `co_await` actually return? [closed]
I have read three articles of lewissbaker, and I am totally lost. And now I have also read https://blog.eiler.eu/posts/20210512/, and I am even more lost. The author gives an example https://gist....
0
votes
1
answer
44
views
C++ Primer 5th Ed - Stanley Lipmann: Question on shared_ptr.unique() used in conjunction with shared_ptr.reset()
First we have a shared_ptr defined as below:
shared_ptr<int> p(new int(42));
According to the text below:
The reset member is often used together with unique to
control changes to the object ...
0
votes
2
answers
68
views
Why does std::coroutine_handle only refer to a coroutine (via raw pointer) instead of owning it (via std::unique_ptr)?
I'm interested in understanding the reason behind the design choice of having std::coroutine_handle be effectively a non-owner of the coroutine state/frame.
I understand that (at least usually?) the ...