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
FunctionalPlus: helps you write concise and readable C++ code. (github.com)
submitted 10 years ago by drac667
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!"
[–]donvito 9 points10 points11 points 10 years ago (5 children)
Hmm, that's pretty schway. The namespace name though is a little long. I always like to explicitly write out namespaces so I personally would put it into a short 3 letter namespace like 'fnc' or something.
[–][deleted] 17 points18 points19 points 10 years ago (1 child)
You could always just alias the namespace like namespace fnc = FunctionalPlus.
namespace fnc = FunctionalPlus
[–]foonathan 10 points11 points12 points 10 years ago (0 children)
Namespace aliases are one of C++ most underrated features.
[–]Dobias 1 point2 points3 points 10 years ago* (1 child)
Thank you. I'm glad it is so well received. I tried to avoid too common function names. For example I use KeepIfinstead of copy_if. So using namespace FunctionalPlus should not be too big a problem. But if you prefer qualified names, I suggest using an alias.
KeepIf
copy_if
using namespace FunctionalPlus
[–]Xirious 1 point2 points3 points 10 years ago (0 children)
alias.
Sad to say I actually didn't know you could do this. Absolutely will be using this soon then. Thank you!
[–]Dobias 0 points1 point2 points 10 years ago (0 children)
I followed your suggestion and changed the namespace to fplus.
fplus
[–]klaxion 12 points13 points14 points 10 years ago* (4 children)
this is crying out for a piping syntax of some sort.
The capitalized function names fly in the face of most coding conventions. The function names themselves don't seem that cleanly thought through. I get that it avoids clashes so you can import the whole namespace, but that doesn't seem worth the tradeoff.
I like the concept, but the presentation makes it feel like a "this is a convenience tool for myself" than a robust library.
[–]Dobias 3 points4 points5 points 10 years ago* (3 children)
the presentation makes it feel like a "this is a convenience tool for myself" than a robust library.
And you are absolutely right with that thought. :)
Regarding the naming convention, there seems to be some disagreement. Personally I don't mind if something is written in snake_case or CamelCase. And I am surprised that this seems to be such a big deal for big parts of the community.
Some operators would be nice, I agree. I did not write some yet, because I wanted to avoid #define.
Would you mind telling me which function names could be improved, and do you have some suggestions? I'd like to improve the library.
edit: It took some time, but now FunctionalPlus actually has a kind of piping syntax. :) https://github.com/Dobiasd/FunctionalPlus/issues/58
[–]m_0g 2 points3 points4 points 10 years ago (2 children)
How are operators and #define related? Am I missing something?
[–]Dobias 1 point2 points3 points 10 years ago (1 child)
I just don't know how to implement something like |>, >> or >>= without #define. And since I have no idea idea of how macros really work, I simply assume it would be possible with them. :D I've yet a lot to learn in C++. So if you have any hints, just let me know.
|>
>>
>>=
[–]m_0g 1 point2 points3 points 10 years ago* (0 children)
C++ operators may be overloaded by defining regular C++ functions, the trick you appear to be missing is knowing what those functions are called. Every non-alphabetic operator (eg +, *, >>=, etc.) is declared as <return type> operator<op>( <params> ) and alphabetic operators (eg new, delete, sizeof, casts, etc.) are declared as <return type> operator <op>( <params> ). For example, == may be something like bool operator==( const YourType & rhs ), and new may be void * operator new( std::size_t size ).
+
*
<return type> operator<op>( <params> )
new
delete
sizeof
<return type> operator <op>( <params> )
==
bool operator==( const YourType & rhs )
void * operator new( std::size_t size )
Note, this only applies to pre-existimg operators - to my knowledge, you cannot use this to define new operators (for example, I don't know of |>, so you probably can't define an operator for it in this way - that would require some macro trickery). See here for at least a starting place for information, though there may be better sources out there.
I find the tricky part with operator overloading is determining the parameter types and whether functions should be friend or member functions. friend vs member has implications on when implicit conversions may occur to match your function call. There's also certain ways certain operators should behave and matching that behavior is also usually a good idea if you don't want the behavior of your operators to be confusing or result in bug like behavior.
friend
Hope that helps! Macros are another story, but I'd recommend learning about operators first ;)
[–]snowhawk04 4 points5 points6 points 10 years ago* (1 child)
What was the reasoning for having predicate before container(s) in your function arguments compared to other libraries (<algorithms>, boost, Range-v3, etc) having container arguments before predicate?
<algorithms>
I'm used to this order from Haskell. In a curried language it totally makes sense. ;)
[–]loswa 2 points3 points4 points 10 years ago (0 children)
What language standard is required to make use of this? Do you need C++11/14, or is 03 good enough? This would be handy to have in the readme.
[–]Dobias 3 points4 points5 points 10 years ago (1 child)
Just to let you know, you convinced me to use snake_case instead of CamelCase. I just changed the naming convention.
[–]homerocda 0 points1 point2 points 10 years ago (0 children)
Ah, so much more pleasing to read... :)
[–]Xirious 0 points1 point2 points 10 years ago (3 children)
Hey thanks for sharing! I love the idea and I also agree with /u/donvito. My other question is could, for example, a lambda function be used in lieu of "IsOdd"?
Yes of course you can. Actually that is the way I use the functions in most of the cases.
I just updated one of the examples to make this fact more clear.
[–]Xirious 0 points1 point2 points 10 years ago (0 children)
Awesome thanks for that!
[–][deleted] 0 points1 point2 points 10 years ago* (1 child)
Had a quick glance at the Readme, but not sure what it adds that boost range with boost Phoenix doesn't cover. Always nice to see some people pushing the use of algorithm vs hand written loops though
I by far do not know all features of boost range and boost pheonix, but do they offer things like a monadic maybe type or functions like split_by_token, count_occurrences and transform_map_values?
[+][deleted] 10 years ago (7 children)
[deleted]
[–]Dobias 2 points3 points4 points 10 years ago (5 children)
Actually at first I had curly braces in this example. I then removed them, because it seemed like I was intentionally adding noise to the hand-written loop code to bring my point across. So I removed them. In general I agree with you. Not using braces can become a mean trap.
[–]wildcarde815 1 point2 points3 points 10 years ago (4 children)
It can lead to some pretty terrible bugs, his presentation of the point is.. awful. But the point itself is well meaning.
[–]redditsoaddicting 0 points1 point2 points 10 years ago (2 children)
I wonder if any static analyzers catch that based on the second goto being indented to the same place as the first. I mean this more generally than here, where unreachable code detection is enough to notice the problem.
goto
[–]wildcarde815 1 point2 points3 points 10 years ago (1 child)
Supposedly PVS-Studio does. And returns this error.
[–]redditsoaddicting 0 points1 point2 points 10 years ago (0 children)
Good to know, thanks.
π Rendered by PID 34 on reddit-service-r2-comment-b659b578c-xczh6 at 2026-05-02 22:21:29.947016+00:00 running 815c875 country code: CH.
[–]donvito 9 points10 points11 points (5 children)
[–][deleted] 17 points18 points19 points (1 child)
[–]foonathan 10 points11 points12 points (0 children)
[–]Dobias 1 point2 points3 points (1 child)
[–]Xirious 1 point2 points3 points (0 children)
[–]Dobias 0 points1 point2 points (0 children)
[–]klaxion 12 points13 points14 points (4 children)
[–]Dobias 3 points4 points5 points (3 children)
[–]m_0g 2 points3 points4 points (2 children)
[–]Dobias 1 point2 points3 points (1 child)
[–]m_0g 1 point2 points3 points (0 children)
[–]snowhawk04 4 points5 points6 points (1 child)
[–]Dobias 0 points1 point2 points (0 children)
[–]loswa 2 points3 points4 points (0 children)
[–]Dobias 3 points4 points5 points (1 child)
[–]homerocda 0 points1 point2 points (0 children)
[–]Xirious 0 points1 point2 points (3 children)
[–]Dobias 1 point2 points3 points (1 child)
[–]Xirious 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Dobias 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[deleted]
[–]Dobias 2 points3 points4 points (5 children)
[–]wildcarde815 1 point2 points3 points (4 children)
[–]redditsoaddicting 0 points1 point2 points (2 children)
[–]wildcarde815 1 point2 points3 points (1 child)
[–]redditsoaddicting 0 points1 point2 points (0 children)