Skip to content

Commit 6d80ba9

Browse files
committed
c++17, structured bindings
1 parent 93afc68 commit 6d80ba9

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎Makefile_many‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ O ?= 0
1414
STD ?= c11
1515
PEDANTIC ?= -pedantic-errors
1616
CFLAGS ?= -g$(G) -march=native -O$(O) -pthread -std=$(STD) -Wall -Wextra $(PEDANTIC) $(CFLAGS_EXTRA) #-pg
17-
MYCXXFLAGS ?= -g$(G) -march=native -O$(O) -pthread -std=c++14 -Wall -Wextra $(PEDANTIC) $(CXXFLAGS_EXTRA) #-pg
17+
MYCXXFLAGS ?= -g$(G) -march=native -O$(O) -pthread -std=c++17 -Wall -Wextra $(PEDANTIC) $(CXXFLAGS_EXTRA) #-pg
1818

1919
LIBS ?= -lm -lrt $(LIBS_EXTRA) #-lGL -lGLU -lglut
2020

‎cpp/tuple.cpp‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ int main() {
2222
/*
2323
# make_tuple
2424
25-
forwards arguments to tuple constructor.
26-
27-
The advantage over the constructor is that since it is a function
28-
template argument deduction can be done, so we don't need to type in
29-
template arguments.
30-
31-
Remember that template argument deduction cannot be done for constructors.
25+
Analogous to make_pair, but with variable number of arguments. Pretty neat.
3226
*/
3327
{
3428
std::tuple<int,char,std::string> t;
@@ -111,6 +105,18 @@ int main() {
111105
// If only we could save both types and assignments...
112106
// http://stackoverflow.com/questions/29312154/how-to-create-a-new-variable-and-use-stdtie-at-the-same-time
113107
// http://codereview.stackexchange.com/questions/61499/a-tuple-unpacking-macro-that-approximates-python-elegance
108+
109+
// Structured bindings
110+
// https://stackoverflow.com/questions/29312154/how-to-create-a-new-variable-and-use-stdtie-at-the-same-time
111+
{
112+
#if __cplusplus >= 201703L
113+
auto tuple = std::make_tuple(1, 'a', 2.3);
114+
auto [ i, c, d ] = tuple;
115+
jassert(i == 1);
116+
assert(c == 'a');
117+
assert(d == 2.3);
118+
}
119+
#endif
114120
}
115121

116122
/*

0 commit comments

Comments
 (0)