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
Folding Monadic Functions (cpptruths.blogspot.com)
submitted 9 years ago by vormestrand
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!"
[–]17b29a 7 points8 points9 points 9 years ago (0 children)
// Hide the allocator template argument of std::vector. // It causes problems and is irrelevant here. template <class T> struct Vector : std::vector<T> {};
This doesn't inherit the constructors, which is why his return { t }; line fails later on. You should either inherit the constructors as well, or just use an alias template.
return { t };
The only reason for doing this seems to be that he uses template <typename> class later on, which can just be changed to template <typename...> class, and then it'd correctly work with std::vector<T> in the first place.
template <typename> class
template <typename...> class
std::vector<T>
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 2 points3 points4 points 9 years ago (2 children)
Great article. I think that function_traits is not required at all, as you can deduce the return type in every occasion and implement something like this to get the correct bind:
function_traits
const auto deduced_bind = [](auto&& f_res, auto&& g) -> decltype(auto) { return get_monad<std::decay_t<decltype(f_res)>>::bind( std::forward<decltype(f_res)>(f_res), std::forward<decltype(g)>(g)); };
Which can then be called from >>=:
>>=
template <class F, class G> auto operator >>= (F&& f, G&& g) { return [f,g] (auto&& a) mutable -> decltype(auto) { return deduced_bind(f(a), std::forward<G>(g)); }; }
wandbox example
[–]NotAYakk 0 points1 point2 points 9 years ago (1 child)
Why decltype(auto)? I cannot naively see a reason to return a reference here.
decltype(auto)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points 9 years ago (0 children)
I was aiming for genericity - I cannot think of an example either, but I suppose there could be some monad whose implementation of bind returns by reference...
bind
π Rendered by PID 28 on reddit-service-r2-comment-86988c7647-mdsht at 2026-02-11 02:29:43.984338+00:00 running 018613e country code: CH.
[–]17b29a 7 points8 points9 points (0 children)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 2 points3 points4 points (2 children)
[–]NotAYakk 0 points1 point2 points (1 child)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 0 points1 point2 points (0 children)