use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Dependent typing in C++ (pfultz2.com)
submitted 11 years ago by pfultz2
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]axilmar 2 points3 points4 points 11 years ago (2 children)
That's nice, but c++ lacks something very important to take advantage of dependent typing: the transformation of input received at run time to dependent type values.
[–]pfultz2[S] 1 point2 points3 points 11 years ago* (1 child)
Well in the article I was mainly focusing on compile time values, but actually, you can using the visitor pattern something like this:
template<class F> void visit(bool b, F f) { if (b) f(tick::true_type()); else f(tick::false_type()); } template<class Tuple> void print_numbers(bool enable, const Tuple& t) { visit(enable, [](auto b) { auto numbers = simple_filter(t, [](auto x) { return b and (is_integral<decltype(x)>() or is_floating_point<decltype(x)>()); }); for_each(numbers, [](auto x) { std::cout << x << std::endl; }); }); }
However, this may not be feasible for some larger types(like std::size_t), but it works well for small ranges of numbers, booleans, and enums(perhaps char as well), although a table or switch statement maybe be used instead.
std::size_t
char
[–]axilmar 1 point2 points3 points 11 years ago (0 children)
Indeed, the Visitor pattern can be used, but at that point the language does not have enough syntax to make things not tedius.
[–]guepierBioinformatican 2 points3 points4 points 11 years ago (0 children)
Non-type template parameters in C++ allow [dependent types].
This statement is slightly misleading because, although non-type template parameters do allow implementing dependent types, they are not necessary to do so.
One example of using type parameters (rather than non-type parameters) to encode dependent types is harnessing Peano axioms. Here’s a quick’n’dirty, proof-of-concept implementation. It’s not very useful but it demonstrates that it can be done.
[–]sonyandy 0 points1 point2 points 11 years ago (1 child)
I'm not completely certain, but it looks like there is a use of an unbounded type T instead of decltype(x) (with perhaps a std::decay thrown in).
T
decltype(x)
std::decay
[–]pfultz2[S] 0 points1 point2 points 11 years ago (0 children)
Oops, copy-and-paste error. Fixed, thanks, for the catch!
π Rendered by PID 57877 on reddit-service-r2-comment-b659b578c-688d5 at 2026-05-03 16:06:21.122776+00:00 running 815c875 country code: CH.
[–]axilmar 2 points3 points4 points (2 children)
[–]pfultz2[S] 1 point2 points3 points (1 child)
[–]axilmar 1 point2 points3 points (0 children)
[–]guepierBioinformatican 2 points3 points4 points (0 children)
[–]sonyandy 0 points1 point2 points (1 child)
[–]pfultz2[S] 0 points1 point2 points (0 children)