struct custom_triple {
int width;
int length;
int age_of_the_captain;
};
custom_triple triple = { 3, 5, 7 };
// this is called a decomposition declaration
auto& [x, y, z] = triple;
assert( &x == &triple.width && &y == &triple.length && &z == &triple.age_of_the_captain );
template<typename Triple>
void generic(Triple triple)
{
auto& [x, y, z] = triple;
}
void triple_check(auto& [x, y, z]);
template<typename Tri>
concept bool Triple = requires(Tri tri) { triple_check(tri); };
template<typename Tri>
concept bool Triple = requires(Tri tri, auto& [x, y, z] = tri) { void(); };
template<typename Tri>
concept bool Triple = requires(Tri tri) {
// must be well-formed for requires expression to be true
auto& [x, y, z] = tri;
};
Wording for structured bindings[1] was voted into the C++ draft at the 2016 Oulu meeting. Structured bindings make it possible to write the following code:
struct custom_triple {
int width;
int length;
int age_of_the_captain;
};
custom_triple triple = { 3, 5, 7 };
// this is called a decomposition declaration
auto& [x, y, z] = triple;
assert( &x == &triple.width && &y == &triple.length && &z == &triple.age_of_the_captain );
I've noticed with interest that as best as I can tell, it is not possible to express e.g. 'this type must be decomposable into a triple'. That is, it is not possible to put precise constraints on the following generic code:
template<typename Triple>
void generic(Triple triple)
{
auto& [x, y, z] = triple;
}
The big, major hurdle is that decomposition declarations are only allowed at block-scope and in for-range declarations.
--
You received this message because you are subscribed to the Google Groups "SG8 - Concepts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concepts+u...@isocpp.org.
To post to this group, send email to conc...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/concepts/.
Stuff
--
You received this message because you are subscribed to the Google Groups "SG8 - Concepts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concepts+u...@isocpp.org.
To post to this group, send email to conc...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/concepts/.
You mean something like a plain struct?struct foo {string a;int b;};That would be great, but we'll need language support (default generation of get<N>, tuple_xxx, anybody?).
Otherwise, all of E's non-static data members shall be public direct members of E or of the same unambiguous public base class of E, E shall not have an anonymous union member, and the number of elements in the identifier-list shall be equal to the number of non-static data members of E. The i-th non-static data member of E in declaration order is designated by mi. Each vi is the name of an lvalue that refers to the member mi of e and whose type is cv Ti, where Ti is the declared type of that member; the referenced type is cv Ti. The lvalue is a bit-field if that member is a bit-field.
--
You received this message because you are subscribed to the Google Groups "SG8 - Concepts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concepts+u...@isocpp.org.
To post to this group, send email to conc...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/concepts/.
Right, we can get decomposition for (many) classes, but they don't otherwise behave as tuples. Unless I'm being dense and missing your point entirely.