This is the single best feature of C++17 that's completely unfucking the SFINAE overloaded template shitstorm that C++...

This is the single best feature of C++17 that's completely unfucking the SFINAE overloaded template shitstorm that C++ is criticized for. Why haven't you grabbed a compiler from your package manager and given C++ another shot yet?

Attached: if constexpr.png (200x44, 7K)

Other urls found in this thread:

github.com/ThePhD/sol2
open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf
twitter.com/SFWRedditImages

Because C++ doesn't have a package manager.

all you need to do under *nix is grab libwhatever-dev and you're all set. no need for some specific ecosystem

>std::cout

bc the only time i encountered c++ was in uni and we used c++89

might as well be a different language now. you can still do all of the same things, but you can specify abstractions and generics in a way other than a command separated mass of words surrounded by eight layers deep

I don't know what to make with C++.

Attached: 1523540960971.png (1902x3854, 474K)

>mfw printf master
the only feature of c++ I've used is methods in objects which is handy for work. Other than that, use pure C.

This also. Outside of objects, C++ looks way too complex

Stick to C and Go, brainlet.

luckily for you, none of the features have been deprecated

I've only used it for making GUIs with Qt and I basically used it as C. If I'm gonna do OOP I'd rather use Java or C#.

If you're trying to persuade others to use C++, why not provide some insight and examples? I want to like it.

>C++ means OOP

Attached: 1300959215207.jpg (488x442, 21K)

>If you're trying to persuade others to use C++
I'm not.

Took a stab and assumed you were OP. Never mind then.

what else would you use it for? if not for OOP, what benefit does c++ have over straight C99?

One of the best libraries I've used recently is Sol2, which lets you embed a Lua interpreter. It just werks and a bunch of the syntax and behind the scenes magic is really only possible in C++. You can say "I want to call this function from Lua" and the library just lets you do it with nothing more than one line exposing it to the interpreter. 10 years ago this would've been a hand-rolled clusterfuck or external tool that created binding code for you, but now it's a single header that only requires you link the Lua library.
github.com/ThePhD/sol2

uhm... is this bait?

generics, anonymous functions, safe pointers, containers. yes some of these might use "objects" under the hood in certain circumstances, but you can write useful C++ programs that never say "class" anywhere

fuck meant to reply to

All of those are classes anyway, you're using OOP one way or the other.

>generics are classes
peak Jow Forums

meh I meant the functors, shared pointers and containers, but be as dense as you want

>j-just because I said it doesn't mean I meant it

auto add( auto a, auto b ) { return a + b; }
is a trivial and useless example but shows generic/template metaprogramming that does not use a class. you can inspect types and make decisions on them at compile time even if the types are just trivial pointers, structs/unions, or "basic types" like int, unsigned long, etc.

auto add = [](auto a, auto b){ return a + b; };
creates an anonymous function that compiles as a function pointer to the specific instantiation of the argument types. there's no more overhead than calling some other function. a lambda doesn't become an object until you start capturing state like
int x = 3;
[&x](int y) { x += y; }(6); // x is now 9;
and yeah, you've created an object, but the abstraction is useful if you're just passing around struct pointers to functions to get the same result.

obviously smart pointers and containers are objects at their core, but the overhead is so trivial you might as well use a vector instead of hand rolling your own resizable array

Yes it does and it's called vcpkg. It's fairly new, but it's maintained by Microsoft and is FOSS and cross-platform (yes, even on Ganoo plus Linocks)

I'm a brainlet who has barely into C++11. Please give me an example of when I should use this feature.

Having objects does not make those OOP. Nice bait anyway

You aren’t actually this retarded right?

Templates. Templates allow you to generate more functionality with less code.

That function signature is a clusterfuck though.

How does that work?
If I require boost on two different projects, will it clutter my storage with multiple copies of it?

How do you use that with existing type traits / sfinae?
Does it evaluate nonexistant members to false?

Lambdas, functional Objects and std::function.
In C, asynchronous libraries (= that use callbacks) are almost unusable because the language doesn't offer capturing state from the calling function (Unless you use apple's proprietary "blocks" extension to C).

modern c++ looks like cancer.
I had a lot of experience using c++ 98/03 with boost libs. That was enough to know that c++ would continue to spiral the drain at ever increasing speed, considering that the standards committee basically just pulls everything from boost (and their ass) for every new version.

>c++
>write code that gets deprecated within several years by the language standard
fucking lmao

Templates also allow you to generate hundreds of pages of obscure compilation errors with less code.

You use your system package manager, idiot!

namespaces

It's pretty easy to scroll to the top of the errors to find the human readable part with the line number of the error.

>If I require boost on two different projects, will it clutter my storage with multiple copies of it?
No. It doesn't have any concept of projects. It's just a package manager. You simply specify where the files go and what libraries you want to download. It lacks the same ease of use as other language package managers like gem (Ruby) or pip (Python). However, I think it's only a matter of time before someone makes a wrapper around vcpkg. What we need now is a way to declare all the dependencies in a file and have some script parse that file and make calls to vcpkg automatically (Similar to "bundle build", if you use Ruby)

Is this a feature of c++17 or of the new version only? Are there good books to learn this new version and not the pajeet tier old one?

You can do this with the detection idiom, now in std::experimental::is_detected

There's nothing wrong with that solution, and not hard to read if you know C++. Metaprogramming/computing with types require a different way of thinking.

It's a good example of pre C++17 code that can be made less verbose with if constexpr. You can get rid of enable_if SFINAE.

>still not as powerful as macros
>still way worse error messages

>the SFINAE overloaded template shitstorm that C++ is criticized for
>"Oh golly, C++ could be a really fine language designed by geniuses if not for the SFINAE overloaded template shitstorm."
Said nobody ever.

Concepts in C++2a will add the new requires syntax which allows you to determine if a new expression is valid.

I've never had to use C++. All that template shit looks awful.

it's just pattern matching using template specialization, easy af.

I wanna like this language but it's just such a fucking mess oh god
Is making a clean and understandable syntax so hard?

Why do I have to write [](){} for a lambda? What would someone who doesn't know C++ lambdas look up after seeing it

making clean syntax while maintaining backward compatibility is hard yah
>Why do I have to write [](){} for a lambda?
you can omit the () for a zero arg function.

Just make C+++, a new version that isn't as cancer to the eyes, while still maintaining C++

Meanwhile in glorious HolyC:
"C++ is niggerlicious";

but itÄs literally not required. you can do it in multiple ways.

where find books on modern c++

It's a combination of namespaces and IO streams, along with operators equivalent of bitwise shift operators.
>It's almost like you're shifting characters into a sequential screen buffer

It is pretty neat.

Attached: 1527095575091.png (562x453, 49K)

template static inline constexpr
nigga why

>std::endl

This is for manually flushing the output. You aren't supposed to put this at the end of every line. Just use a regular newline.

>template
So I can take guaranteed statically known arguments
>static inline
because it's defined in a header
>constexpr
So that it can be used in constant expressions and be evaluated at compile time

What are you? a brainlet?

constexpr implies inline. template implies inline also.
>because it's defined in a header
you only need inline for this, static is unnecessary

Also, make it a using declaration rather than a function. The interface for that is much nicer when you're only interested in "returning" a type.

seems unbelievably useless and yet another addition to the byzantine heap that is sepples

>auto add( auto a, auto b ) { return a + b; }
that's exactly how 'nerics should be implemented in go, as far as the function signature is concerned

vcpkg being the motherfucker that hangs around doing nothing in 5x processes and takes 300MB of RAM per process

at this point you're arguing with the compiler to do implement the utmost trivial trash code

it's useful for template metaprogramming and is much simpler to use than previous alternatives like SFINAE while also not adding much to the complexity of the language in terms of usability.
if constexpr is an example of a well implemented feature, unlike most of sepples

>you can omit the () for a zero arg function.
that's even worse, it introduces yet another quirk to interrupt the reader

i've never been under any delusion that template metaprogramming is anything other than mental masturbation though

>SFINAE
i have no idea what this is. i googled it and it just seemed to be a bunch of wank with no real-world application. one might as well be talking about monoids and monads -- i do not care.

>while also not adding much to the complexity of the language
indeed; at this point it's pissing in a sea of piss

C++ users should just convert to rust, taking their love of inscrutable code and esoteric features to its logical conclusion.

>constexpr implies inline. template implies inline also.
Oh, didn't know this.

>you only need inline for this, static is unnecessary
You sure? I remember needing it for some reason. Can you explain further?

>make it a using declaration
The function is an implementation detail that is literally used only once, so I didn't bother with it.

lmao I haven't got a clue what you're babbling on about. What "arguing" are you talking about.
It's a function used to optimize the size of the discriminator at compile time for an std::variant implementation to increase the chance that the compiler is able to use load/store combining to optimize copies etc.

Attached: 1503293681766.png (571x22, 5K)

>hur classes == OOP
End yourself.

who gives a shit

Then don't fling your shit in the first place, nigger monkey.

Answer me you niggers.
None of the books in the booklist/megatorrent are recent enough to cover even c++ 11

Don't waste your time mindfucking yourself with sepples.

How do you get mind fucked by C++

HAVE FUN

open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf

Every .cpp file gets compiled to one .o file. The .o files are then linked into an executable.

By default symbols are given external linkage. That means only one definition of this symbol can exist across all .o files. If zero or many copies of a symbol exist then the linker craps out because it doesn't know which to choose. This is why it's important to define regular functions in exactly one .cpp file.

The static modifier gives a symbol internal linkage. For static symbols defined in a header, every .o file gets its own copy of the symbol if it needs to create one without telling the linker. This is one way to define something in a header file without the linker crying.

The inline modifier relaxes the linker's rules. The compiler can choose whether or not it wants to emit a symbol in a given .o file if a symbol is inline. If there are multiple definitions across multiple .o files then the linker ensures they are all the same before combining them into one symbol.

So for putting things in headers you can either choose static or you can choose inline. inline is preferred because it means you don't get duplicated functions. If the compiler decides not to inline your call to foo() in all your .o files then it is calling a different function each time with a static foo() and it is calling the same function each time with an inline foo(). It benefits binary size and cache utilization at the expense of linking time.

static inline means the same thing as static because the linker never interacts with static symbols for the inline part to matter. You choose static inline when you write the function is in a header because some compilers raise warnings for unused static functions.

You mostly see static inline in C code, because inline means something different in C. Functions in headers in C are usually static inline while functions in headers in C++ are usually just inline.

Templates belong in headers so they get inline implicitly.

Thanks senpai. I see now.

Start a blog

Every time I try to code C++ while only knowing C

Attached: what_the_fuck_am_i_reading.jpg (400x400, 54K)

This

if constexpr is quite useful but it isn't a replacement for templates

>i've never been under any delusion that template metaprogramming is anything other than mental masturbation though
they are useful for the same reason macros are useful in C (and in any other language that has macros including lisp, rust, D, etc)

>i have no idea what SFINAE is and it just seemed to be a bunch of wank with no real-world application
it really isn't that hard to understand if you had done any serious work in a static typed language

That's the canonical way, but you can still use the C library (printf) or other frameworks (Qt).

Nowadays C++ is as much a generic programming language as an OO language.

Because I am paid to use R and Python. No need for anything else.

That's because you're not meant to print output to a console in a real system. Most real c++ output logs look like LOG_WARN

I'm interested to see how the Jai language turns out when Blow releases it to the public.
A slimmed down C++ which is less retarded than C, but has some neat helpers built in is a godsend.
I'm not sure how I feel about the syntax though.

You can make it a bit more like C by doing this:
template
void print(std::ostream &stream, Args&&... args) {
(stream

>std::endl;

please stop doing this unless you know what it does. seriously fucking stop. i bet your libstdc++ fucking line buffers just fine on terminal devices already.

FUCK

if constexpr is completely worthless. Both sides of the conditional have to be valid code so it does not help at all in simplifying templates. Almost every new "feature" that has been added to c++ is horrifically ugly or completely useless.

Pretty much pointless, given that the language itself is just a piece of the puzzle: build systems, package management, libraries, tooling (static/dynamic analysis, debuggers, etc...), are also critical.