Comments (4)
In addition to the existing Range-based For Loop example, one for C++17 Structured Bindings may be a good candidate, e.g:
#include <cstdio>
#include <tuple>
auto mypair() {
return std::make_tuple("hello", 1);
}
int main() {
auto [c, n] = mypair();
printf("c=%s, n=%d\n", c, n);
}
This emits:
int main() {
auto __mypair9 = mypair();
std::tuple_element<0, std::tuple<const char *, int> >::type&& c = get<0ul>(__mypair9);
std::tuple_element<1, std::tuple<const char *, int> >::type&& n = get<1ul>(__mypair9);
printf("c=%s, n=%d\n", c, n);
}
from cppinsights.
#include <cstdio>
#include <string>
#include <tuple>
#include <vector>
template <typename Tuple_t>
void fillTuples(std::vector<Tuple_t> tuples) {
tuples.emplace_back("hello", 1);
}
int main() {
std::vector<std::tuple<std::string, int>> tuples;
fillTuples(tuples);
for (auto [s, n] : tuples) {
printf("c=%s, n=%d\n", s.c_str(), n);
}
}
from cppinsights.
What about recursive templates?
#include <cstdio>
#include <vector>
template<int n>
struct A
{
static const auto value = A<n-1>::value+n;
};
template<>
struct A<1>
{
static const auto value = 1;
};
int main()
{
printf("c=%c\n", A<5>::value);
}
from cppinsights.
Hello,
there is now an examples page. Feel free to open pull request for more examples.
Andreas
from cppinsights.
Related Issues (20)
- invoke lambda with `temp.operator()()` generate wrong code. HOT 1
- It does not show vtable and vptr assignment HOT 2
- Error building inside clang source tree HOT 1
- About nested class inside a class template HOT 1
- Specialization of variable templates misses type deduction and `template` HOT 1
- Would it possible to have more educational things supported? HOT 6
- Fold expressions miss parentheses HOT 4
- Site is down HOT 3
- cppinsights.io doesn't show the what is listed in github.com HOT 1
- Errors in transforming `struct T {} var` HOT 2
- About the release scheme HOT 1
- Errors in transforming "int& a = A()" HOT 1
- Pack expansion in ctor call transformed into invalid c++
- Class template argument deduction not working - cpp17 HOT 2
- Add support for `SourceLocExpr` HOT 4
- Build on visualstudio 2019 get ascii, utf errors HOT 1
- Variant initialization improvisation (suggestion) HOT 4
- std::move redundant?? HOT 5
- crash when parse cpp file HOT 1
- different result from godbolt HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppinsights.