• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 01:08
CET 07:08
KST 15:08
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
StarCraft Evolution League (SC Evo Biweekly) RSL Offline Finals Info - Dec 13 and 14! RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread ZeroSpace Megathread Nintendo Switch Thread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1551 users

The Big Programming Thread - Page 508

Forum Index > General Forum
Post a Reply
Prev 1 506 507 508 509 510 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
August 05 2014 18:17 GMT
#10141
On August 06 2014 01:01 bangsholt wrote:
Show nested quote +
On August 05 2014 13:10 darkness wrote:
I know Linus Torvalds' comment about C++ has been brought up many times, yet I know almost nothing about C++. But isn't he too extreme? I've heard C++ has a bunch of everything but I'm sure if there are certain programming standards within an organisation, then even that could be more or less avoided.

Frankly, his bite at OOP makes me think he is that retarded. Yes, Linus is a legend but his opinions aren't.


Try to learn C++, it's a carwreck of a language because you have three different ISOs, you have the C++11, C++03, C++98 which all strives not to introduce any major code breaking, meaning that you have 3 distinct ways of programming in C++ that are all valid, correct and will compile as expected, which unless as you say, you have a coding standard in place, everyone will use what they are most familiar with.

It's only natural to be wanting to use the newest features, which is why quite a few C++ codebases are scattered across all of standards.

So basically you *need* to remove parts of the language that you don't want, in order to have a subset of the language that is possibly to understand thoroughly.

With regards to the OOP comment, why do you think he's retarded? No matter how you look at it, you do lose *some* (not much, but some) performance by using OOP (i.e. Java/C# is ~5-10% slower in most cases), so when performance is the most important thing, you go with C on Linux - which was one of the main criteria that was behind the decision not to use Monotone when the big switch of version control software happened with the linux kernel.


freedom and backward compability?
terrible! grumble grumble. hiss!
conspired against by a confederacy of dunces.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
August 05 2014 21:06 GMT
#10142
On August 06 2014 02:54 tofucake wrote:
I just really can't get past his "it has lots of bad programmers so it's a bad language" argument, it makes no sense.

And performance is usually not significant enough a factor to say "C always over C++". Hell, Northrup Grumman uses loads of .Net and they have a lot of stuff that relies on performance (e.g. Predator drones).

Torvalds falls into the category of fantatic, in the true sense of the word. He sees languages as a way of life, not as a tool. Different tools for different jobs.

"Lots of bad programmers => bad programming language" argument may be stupid,

but "language very hard to master (for no good reason) => lots of bad programmers"
and "language very hard to master (for no good reason) => bad programming language" make a lot of sense.

Besides, I don't think "different tools for different jobs" is applicable here. C can always be used in place of C++, so if someone (like Linus) doesn't like C++ and/or OOP, there's nothing wrong with using C.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2014-08-05 21:20:49
August 05 2014 21:11 GMT
#10143
On August 06 2014 06:06 delHospital wrote:
Show nested quote +
On August 06 2014 02:54 tofucake wrote:
I just really can't get past his "it has lots of bad programmers so it's a bad language" argument, it makes no sense.

And performance is usually not significant enough a factor to say "C always over C++". Hell, Northrup Grumman uses loads of .Net and they have a lot of stuff that relies on performance (e.g. Predator drones).

Torvalds falls into the category of fantatic, in the true sense of the word. He sees languages as a way of life, not as a tool. Different tools for different jobs.

"Lots of bad programmers => bad programming language" argument may be stupid,

but "language very hard to master (for no good reason) => lots of bad programmers"
and "language very hard to master (for no good reason) => bad programming language" make a lot of sense.

Besides, I don't think "different tools for different jobs" is applicable here. C can always be used in place of C++, so if someone (like Linus) doesn't like C++ and/or OOP, there's nothing wrong with using C.


Well, I disagree even though I don't code in C++. At the very least, C++ has OOP which greatly simplifies complexity and promotes reusability. Sorry, but C fails as soon as high level stuff is needed. C++ has too much garbage? Java/C# have garbage collection? Here comes Objective-C. Objective-C supports manual memory management as well.

I don't like Objective-C syntax and that is mostly bound to Mac OS X, and I don't own Apple's OS. However, a lot of the stuff I had to deal with is high level enough and looks promising. E.g. cells and GUI are very, very easy to do. Storyboards make it stupidly simple now.

Edit: Oh yeah, C lacks so many essential libraries that it's not even funny.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
Last Edited: 2014-08-05 22:15:47
August 05 2014 22:10 GMT
#10144
On August 06 2014 06:11 darkness wrote:
Show nested quote +
On August 06 2014 06:06 delHospital wrote:
On August 06 2014 02:54 tofucake wrote:
I just really can't get past his "it has lots of bad programmers so it's a bad language" argument, it makes no sense.

And performance is usually not significant enough a factor to say "C always over C++". Hell, Northrup Grumman uses loads of .Net and they have a lot of stuff that relies on performance (e.g. Predator drones).

Torvalds falls into the category of fantatic, in the true sense of the word. He sees languages as a way of life, not as a tool. Different tools for different jobs.

"Lots of bad programmers => bad programming language" argument may be stupid,

but "language very hard to master (for no good reason) => lots of bad programmers"
and "language very hard to master (for no good reason) => bad programming language" make a lot of sense.

Besides, I don't think "different tools for different jobs" is applicable here. C can always be used in place of C++, so if someone (like Linus) doesn't like C++ and/or OOP, there's nothing wrong with using C.


Well, I disagree even though I don't code in C++. At the very least, C++ has OOP which greatly simplifies complexity and promotes reusability.

There are operating systems, video games, compilers, interpreters, crypto libraries, codecs, web servers, and many other big software projects written in C. If you like OOP, go ahead, use it to the fullest extent. But don't claim that OOP is some kind of a silver bullet, or that it's impossible/more difficult to write maintainable programs in other paradigms.

Wait, were you trying to say that C++ is easier than C? If so, then I'm sorry, but to me that's a crazy statement.


C fails as soon as high level stuff is needed

Don't use C/C++/assembly/Fortran/Rust/... for high level stuff.


Edit: Oh yeah, C lacks so many essential libraries that it's not even funny.

What? I don't think there's any other language with as many libraries as C.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2014-08-05 23:56:41
August 05 2014 23:54 GMT
#10145
I'm not saying OOP is a silver bullet. I'm saying it reduces complexity and promotes reusability. And I never said C++ is easier than C, I said if code in C++ applies OOP, then it's likely the code may experience what I said about OOP earlier.

With regard to less librabries in C, well, the language's API is poor to me. I don't see any ADT (e.g. linked list) within the language. You either have to code it or borrow 3rd party code. I really don't like languages like C which force you to start from scratch.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
August 06 2014 16:06 GMT
#10146
On August 06 2014 08:54 darkness wrote:
I'm not saying OOP is a silver bullet. I'm saying it reduces complexity and promotes reusability. And I never said C++ is easier than C, I said if code in C++ applies OOP, then it's likely the code may experience what I said about OOP earlier.

With regard to less librabries in C, well, the language's API is poor to me. I don't see any ADT (e.g. linked list) within the language. You either have to code it or borrow 3rd party code. I really don't like languages like C which force you to start from scratch.

There is no linked list implementation in the small standard library, but there's one in the linux kernel. It's surprisingly reusable, no need to copy-paste any code.

Yes, there is no concept of nicely importable modules/libraries in C, but is it really any better in C++? And even if you like std::list more, that's thanks to templates, not OOP.

I'll be honest: to me C is a beautiful language, and I just can't stand when people shit on C, and claim that the C++ frankenstein created from merging high- and low-level concepts into an unusable mess (e.g. exceptions + manual memory management headache) is an improvement.
nunez
Profile Blog Joined February 2011
Norway4003 Posts
August 06 2014 16:12 GMT
#10147
they're merged into an unusable mess in the same way you merge an egg and a hammer into an unusable mess if you put them in the same drawer.

there's nothing stopping you from not using exceptions.

programming is a discipline, and you cry about having to be disciplined.
conspired against by a confederacy of dunces.
aksfjh
Profile Joined November 2010
United States4853 Posts
August 06 2014 16:48 GMT
#10148
Is there anything in C++ that you simply cannot do in C? As in, it's impossible (as opposed to simply impractical)?
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2014-08-06 17:09:39
August 06 2014 17:02 GMT
#10149
--- Nuked ---
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-08-06 18:04:57
August 06 2014 17:18 GMT
#10150
link is a doubly linked list, forward_list is singly linked list.

cpp is used in state of the art products in the real time industry as mentioned before, there's not any merit in the performance argument wrt c. speaking of performance i was starting to flip over into panic mode today when my lexer spent way too long time on some (relatively) big files (+5k lines). the culprit was constructing std::strings from the lexemes in char*'s.

i remembered the calm words of stroustrup, "did you turn off debug mode yet". no, i hadn't. in release mode it went two orders of magnitude faster, and it was not issue anymore. a sigh of relief.

@aksfjh
at least in theory i'd expect that any program implemented in c would have an 'isomoprhic' implementation in cpp and visa versa. i am naive and ignorant though. but i'd also expect that supplying template / template metaprogramming induced functionality in libraries to its user would not be feasible to replicate in C, allthough the preprocessor is pretty badass.

for the record i think C seems like a beautiful language too, but why wouldn't you in addition to it have access to templates?
conspired against by a confederacy of dunces.
Zocat
Profile Joined April 2010
Germany2229 Posts
August 06 2014 17:49 GMT
#10151
On August 07 2014 01:06 delHospital wrote:
Show nested quote +
On August 06 2014 08:54 darkness wrote:
I'm not saying OOP is a silver bullet. I'm saying it reduces complexity and promotes reusability. And I never said C++ is easier than C, I said if code in C++ applies OOP, then it's likely the code may experience what I said about OOP earlier.

With regard to less librabries in C, well, the language's API is poor to me. I don't see any ADT (e.g. linked list) within the language. You either have to code it or borrow 3rd party code. I really don't like languages like C which force you to start from scratch.

There is no linked list implementation in the small standard library, but there's one in the linux kernel. It's surprisingly reusable, no need to copy-paste any code.


Not useable at all, since I didn't see a license notice (thus normal copyright applies, which means no one can use it).
Linux kernel overall is GPL, thus not useable.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
August 06 2014 17:52 GMT
#10152
we meet again crazy zero casting


#define list_entry(ptr, type, member) ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
There is no one like you in the universe.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2014-08-06 18:03:26
August 06 2014 18:00 GMT
#10153
--- Nuked ---
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
August 06 2014 18:28 GMT
#10154
On August 07 2014 03:00 Nesserev wrote:
Show nested quote +
On August 07 2014 02:18 nunez wrote:
link is a doubly linked list, forward_list is singly linked list.

Even when doubly linked, it's still a lot slower ^^

Show nested quote +
On August 07 2014 02:52 Blisse wrote:
we meet again crazy zero casting


#define list_entry(ptr, type, member) ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

wtf is this bullsh!t??


http://isis.poly.edu/kulesh/stuff/src/klist/

under "How Does This Work?"
There is no one like you in the universe.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
Last Edited: 2014-08-06 21:40:12
August 06 2014 21:01 GMT
#10155
On August 07 2014 02:02 Nesserev wrote:
Well, memory leakage in C++ due to exceptions hasn't been a problem for a long time now. Just applying RAII and using smart pointers has been a great way to deal with this, and since C++11, it's part of the standard library. There's almost never a good excuse to use a naked new/deletes... and if you see someone still use them, be kind enough to spread the word.

RAII -- I agree. Smart pointers -- for God's sake, no! Use them only if they really make sense... and if they do, then you should probably be using a higher level language anyway. Using "smart pointers" liberally (especially shared pointers) in C++ is a code smell. Even Rust's unique pointers, which do not have any runtime overhead, have been moved from the core to a library to discourage overuse.


Certain programming paradigms have been designed with certain benefits in mind, hence the reason why it's easier to use certain programming paradigms for certain projects. Denying this is ridiculous...

That's not true. If you're talking about mainstream languages, programming paradigms are mostly religion. Every reasonable project can be coded using object-oriented, functional, or good old procedural programming just as well.


Also, on the topic of linked lists, the reason why there is no linked list in C++, is that linked lists are really slow... on paper they sound nice, but in practice, due to the linear searches, they're really slow. Vectors are a lot faster.

Linked lists aren't "slow". Every data structure has different applications.


C++ is an improvement over C to accommodate the general programmer's need in my opinion.

Then we disagree

On August 07 2014 01:12 nunez wrote:
they're merged into an unusable mess in the same way you merge an egg and a hammer into an unusable mess if you put them in the same drawer.

there's nothing stopping you from not using exceptions.

programming is a discipline, and you cry about having to be disciplined.

If I'm writing the main function, you're right, I can just not use exceptions. However, if I want my code to be used in other projects, I do have to think of exceptions, make sure everything is "safe enough", and document it.

On August 07 2014 02:49 Zocat wrote:
Show nested quote +
On August 07 2014 01:06 delHospital wrote:
On August 06 2014 08:54 darkness wrote:
I'm not saying OOP is a silver bullet. I'm saying it reduces complexity and promotes reusability. And I never said C++ is easier than C, I said if code in C++ applies OOP, then it's likely the code may experience what I said about OOP earlier.

With regard to less librabries in C, well, the language's API is poor to me. I don't see any ADT (e.g. linked list) within the language. You either have to code it or borrow 3rd party code. I really don't like languages like C which force you to start from scratch.

There is no linked list implementation in the small standard library, but there's one in the linux kernel. It's surprisingly reusable, no need to copy-paste any code.


Not useable at all, since I didn't see a license notice (thus normal copyright applies, which means no one can use it).
Linux kernel overall is GPL, thus not useable.

You're probably right wrt the license, all I meant was that there are linked list libraries, and you don't have to "borrow code" or start from scratch.

On August 07 2014 02:18 nunez wrote:
for the record i think C seems like a beautiful language too, but why wouldn't you in addition to it have access to templates?

"In anything at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away."

There's not many things I like in C++, but I guess templates are one of the nicer features (why are they Turing complete, though!?).
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-08-08 21:34:19
August 07 2014 00:04 GMT
#10156
      
heap-based, bounded variant, copy/move and static visitors



the deal


in the talk inheritance is the base class of all evil (source) a dude demonstrates an example of implementing polymorphic behaviour for types without requiring that they are members of same class hierarchy. the jist is that you pass values of the types you want polymorphed to a holder class. a (private) abstract class (concept) is defined inside the holder class, as well as a (private) derived template class (model). the value the holder is constructed with is forwarded to the model, which is instantiated with the type of that value and constructed with the value itself. the holder class holds these models through a pointer to concept. an interface is defined on the concept which is exposed through holder.

this is a variation where it's also assumed that the types of the values passed to the holder is known: T:={t⁰, ..., tⁿ}. with this additional piece of info we define a variant type, which holds a value of one of these types in the same fashion as the holder. it facilitates static visitors instead of defining an interface on the concept.

the latter is achieved by generating function spaces (an array of function pointers {p⁰, ..., pⁿ}, where pⁱ is a template member function instantiated with tⁱ ∈ {t⁰, ..., tⁿ}) and keeping track of, and dispatching on, the index of the type of the held value (tⁱ in T := {t⁰, ..., tⁿ} -> i). copy and move semantics are implemented in similar fashion.



the veal


to showcase i wrote a small example with expression trees consisting of binary additions, subractions and integers.
the additions and subtractions are represented by a binop type which have children lhs, rhs. copy / move semantics are defaulted. the integers are just ints.
the tree is represented by a node type which is a variant over these three different types. this node is the 'visitable' object.

the visitors (a printer and an evaluator) recursively call themselves on node, traversing the expression tree top to bottom.

+ Show Spoiler [node_t.hpp] +
#pragma once
#include<utility>
#include<is_member.hpp>
#include<variant_t.hpp>

namespace tags{

struct add{};
struct sub{};

}

template<class tag> struct binop_t;
typedef binop_t<tags::add> add_t;
typedef binop_t<tags::sub> sub_t;

typedef variant_t<add_t,sub_t,int> node_t;

template<class tag>
struct binop_t{
node_t lhs,rhs;
binop_t(node_t&& _lhs,node_t&& _rhs):
lhs(std::move(_lhs)),
rhs(std::move(_rhs))
{}
binop_t()=delete;
binop_t(binop_t&& binop)=default;
binop_t& operator=(binop_t&& binop)=default;
binop_t(const binop_t& binop)=default;
binop_t& operator=(const binop_t& binop)=default;
};


+ Show Spoiler [printer_t.hpp] +

#pragma once
#include<iostream>
#include<node_t.hpp>
#include<apply_visitor.hpp>

struct printer_t{
typedef void return_type;
int indentation{1};
std::ostream& out;

void indent(){ for(int i=0;i<indentation;++i) out<<" "; }

template<class T>
void print(const T& obj){
indent();
out<<obj<<std::endl;
}

printer_t(std::ostream& _out):out(_out){}

void operator()(int node){ print(node); }

template<class tag>
void operator()(const binop_t<tag>& node){
print(is_add<tag>::value?'+':'-');
++indentation;
apply_visitor(*this,node.lhs);
apply_visitor(*this,node.rhs);
--indentation;
}

};


+ Show Spoiler [evaluator_t.hpp] +

#pragma once
#include<apply_visitor.hpp>
#include<node_t.hpp>

struct evaluator_t{
typedef int return_type;

int operator()(int node)const{ return node; }

int operator()(const add_t& node)const{
int lhs=apply_visitor(*this,node.lhs);
int rhs=apply_visitor(*this,node.rhs);
return lhs+rhs;
}

int operator()(const sub_t& node)const{
int lhs=apply_visitor(*this,node.lhs);
int rhs=apply_visitor(*this,node.rhs);
return lhs-rhs;
}

};


+ Show Spoiler [main.cpp] +

#include<exception>
#include<iostream>
#include<sstream>
#include<vector>

#include<apply_visitor.hpp>
#include<node_t.hpp>
#include<printer_t.hpp>
#include<evaluator_t.hpp>

using namespace std;

int main(){

try{
//some copy / move semantics
node_t node0(add_t(1,1)); //add_t value ctor @ callsite,
//add_t move ctored @ node0
node_t node1(node0); //add_t copy ctor @ node1 <- node0
node_t node2(std::move(node1)); //add_t move ctor @ node2 <- node1
node_t node3=node2; //add_t copy asgn @ node3 <- node2
node_t node4=std::move(node3); //add_t move asgn @ node4 <- node3
//make some nodes
vector<node_t> nodes{
add_t(
sub_t(4,2),
add_t(0,4)
),
2,
sub_t(
add_t(sub_t(0,4),add_t(2,0)),
add_t(sub_t(4,2),add_t(0,4))
),
add_t(
sub_t(
2,
add_t(sub_t(0,4),add_t(add_t(sub_t(2,0),add_t(4,2)),0))
),
sub_t(
add_t(sub_t(4,2),add_t(0,4)),
add_t(2,add_t(0,sub_t(4,sub_t(2,0))))
)
)
};
//loop, print and evaluate
for(const auto& root:nodes){
stringstream ast;
apply_visitor(printer_t(ast),root);
int result=apply_visitor(evaluator_t(),root);
cout<<"\nast:\n"<<ast.str()<<"\nresult: "<<result<<"\n\n";
}

}catch(exception const& e){
cout<<"exception caught: "<<e.what()<<endl;
}
return 0;
}


+ Show Spoiler [terribly formatted output] +
[jeh@gimli workbench]$ make
g++ -c -std=c++1y -I. -Wfatal-errors -fdiagnostics-color -fmessage-length=64 -ggdb main.cpp
g++ -o workbench main.o
rm -rf *o
[jeh@gimli workbench]$ ./workbench

ast:
+
-
4
2
+
0
4

result: 6


ast:
2

result: 2


ast:
-
+
-
0
4
+
2
0
+
-
4
2
+
0
4

result: -8


ast:
+
-
2
+
-
0
4
+
+
-
2
0
+
4
2
0
-
+
-
4
2
+
0
4
+
2
+
0
-
4
-
2
0

result: 0





frankensteins monster


metafuncions

is member
      value metafunction
    instantiated with type uⁱ ∈ U and typeset T:={t⁰,...,tⁿ}, the type is_member<uⁱ,T> has member
          static const bool value := (true if uⁱ ∈ T, false otherwise).
+ Show Spoiler [is_member.hpp] +
#pragma once
namespace guts{

template<class u_i,class... t_k>
struct
is_member_impl;

template<class u_i,class t_j,class... t_k>
struct
is_member_impl<u_i,t_j,t_k...>:
is_member_impl<u_i,t_k... >
{};

template<class t_i,class... t_k>
struct
is_member_impl<t_i,t_i,t_k...>
{ static const bool value=true; };

template<class u_i>
struct
is_member_impl<u_i>
{ static const bool value=false; };

template<class u_i,class... t_n>
using
is_member=
is_member_impl<u_i,t_n...>;

}


index_of
      value metafunction
    instantiated with type tⁱ ∈ T:={t₀,...,tⁿ} and T, the type index_of<tⁱ,T> has member
          static const int value := i
+ Show Spoiler [index_of.hpp] +
#pragma once
namespace guts{

template<class t_i,int j,class... t_j>
struct
index_of_impl;

template<class t_i,int j,class t_j,class... t_k>
struct
index_of_impl<t_i,j ,t_j,t_k...>:
index_of_impl<t_i,j+1,t_k... >
{};

template<class t_i,int i,class... t_k>
struct
index_of_impl<t_i,i,t_i,t_k...>
{ static const int value=i; };

template<class t_i,class... t_k>
using
index_of=
index_of_impl<t_i,0,t_k...>;

}


type_at
      type metafunction
    instantiated with integer i ∈ {0,...,n} and T:={t⁰,...,tⁿ} and T, the type type_at<i,T> has nested typedef
          type := tⁱ
+ Show Spoiler [type_at.hpp] +
#pragma once
namespace guts{

template<int k,class... t_j>
struct
type_at_impl;

template<int k,class t_i,class... t_j>
struct
type_at_impl<k ,t_i,t_j...>:
type_at_impl<k+1,t_j... >
{};

template<class t_i,class... t_k>
struct
type_at_impl<0,t_i,t_k...>
{ typedef t_i type; };

template<int k,class... t_n>
using
type_at=
type_at_impl<k,t_n...>;

}


piece de resistance

apply_visitor
      function
+ Show Spoiler [apply_visitor.hpp] +
#pragma once
#include<utility>

template<class visitor_t,class visitable_t>
decltype(auto) apply_visitor(visitor_t&& visitor,visitable_t&& visitable){
return visitable.accept(std::forward<visitor_t>(visitor));
}


variant_t
      type
    variant_t<T:={t⁰, ..., tⁿ}> is a heap-based, bounded variant with copy/value semantics that facilitates constant dispatch of static visitors.

    holds the value in the same fashion as holder. also has int index which holds the index of the values type: t ∈ T in T.

    provides value constructor for x-values of types in T, as well as copy / move semantics.
    in the constructors the index is copied from the variant you are constructing from.
    in the assignement it is assumed that the rhs can be casted to the type of the value the lhs is currently holding.

    dispatch on index is done through the mechanism explained in the previous sections.
    the exposed function call is named some_name, while some_name's implementation for a given tⁱ ∈ T is in some_name_impl.
    the functions space is stored in the arrays called impls.
+ Show Spoiler [variant_t.hpp] +

#pragma once
#include<cassert>
#include<array>
#include<memory>
#include<type_traits>
#include<utility>
#include<index_of.hpp>
#include<is_member.hpp>
#include<type_at.hpp>
#include<type_traits>

template<class... t_n>
class variant_t{
public:

template<class t_i>
using index_of=guts::index_of<t_i,t_n...>;

template<class u_i>
using is_member=guts::is_member<u_i,t_n...>;

template<int i>
using type_tag=guts::type_at<i,t_n...>;

static const int rank=sizeof...(t_n);

template<class t_i,class type=void>
using enabler=std::enable_if_t<is_member<t_i>::value,type>;

private:

struct concept_t{ virtual ~concept_t(){} };

template<class t_i>
struct model_t:concept_t{
t_i data;
model_t(const t_i& _data):data(_data){}
model_t(t_i&& _data):data(std::move(_data)){}
};

std::unique_ptr<concept_t> model_ptr;
int index;

template<class t_i>
t_i& as()
{ return static_cast<model_t<t_i>&>(*model_ptr).data; }

template<class t_i>
void copy_ctor_impl(const variant_t& object)
{ model_ptr=std::make_unique<model_t<t_i>>(object.as<t_i>()); }

template<class t_i>
variant_t& copy_asgn_impl(const variant_t& object){
as<t_i>()=object.as<t_i>();
return *this;
}

template<class t_i>
void move_ctor_impl(variant_t&& object)
{ model_ptr=std::make_unique<model_t<t_i>>(std::move(object.as<t_i>())); }

template<class t_i>
variant_t& move_asgn_impl(variant_t&& object){
as<t_i>()=std::move(as<t_i>());
return *this;
}

public:

variant_t()=delete;

variant_t(const variant_t& object):
index(object.index){

static const std::array<
void(variant_t::*)(const variant_t&),
rank
> impls{ &variant_t::copy_ctor_impl<t_n>... };

(this->*impls[index])(object);
}

variant_t& operator=(const variant_t& object){

static const std::array<
variant_t&(variant_t::*)(const variant_t&),
rank
> impls{ &variant_t::copy_asgn_impl<t_n>... };

return (this->*impls[index])(object);
}

variant_t(variant_t&& object):
index(object.index){

static const std::array<
void(variant_t::*)(variant_t&&),
rank
> impls{ &variant_t::move_ctor_impl<t_n>... };

(this->*impls[index])(std::move(object));
}

variant_t& operator=(variant_t&& object){

static const std::array<
variant_t&(variant_t::*)(variant_t&&),
rank
> impls{ &variant_t::move_asgn_impl<t_n>... };

return (this->*impls[index])(std::move(object));
}

template<class u_i, class = enabler<u_i>>
const u_i& as() const
{ return static_cast<const model_t<u_i>&>(*model_ptr).data; }


template<class u_i,class = enabler<u_i>>
variant_t(u_i&& _data):
index(index_of<u_i>::value),
model_ptr(new model_t<u_i>(std::forward<u_i>(_data)))
{}

~variant_t(){}

private:

template<class t_i,class visitor_t>
decltype(auto)
accept_impl(visitor_t&& visitor)
{ return visitor(as<t_i>()); }

template<class t_i,class visitor_t>
decltype(auto)
accept_impl(visitor_t&& visitor) const
{ return visitor(as<t_i>()); }

public:

template<class visitor_t>
decltype(auto)
accept(visitor_t&& visitor){

typedef typename
std::decay_t<visitor_t>::return_type
(variant_t::*accept_impl_t)(visitor_t&&);

static const std::array<
accept_impl_t,
rank
> impls{&variant_t::accept_impl<t_n,visitor_t>...};

return (this->*impls[index])(std::forward<visitor_t>(visitor));
}

template<class visitor_t>
decltype(auto)
accept(visitor_t&& visitor) const{

typedef typename
std::decay_t<visitor_t>::return_type
(variant_t::*accept_impl_t)(visitor_t&&) const;

static const std::array<
accept_impl_t,
rank
> impls{&variant_t::accept_impl<t_n,visitor_t>...};

return (this->*impls[index])(std::forward<visitor_t>(visitor));
}

};




dunno if i have time to polish this more before the weekend, so just gonna post in now and fix it up a bit later.
maybe not bugfree, typos, abusing set notation, visitor pattern. the variant has glaring weaknesses etc, some of them i am aware of, some of them i am not..

adding functionality is easy, just define a visitor, adding types is painful, you might have to further specialize several visitors. and a static array |T| long of function pointers for each visitor...

haven't figured out how to enable / disable copy / move based on if all the types in T is copy constructible, asignable etc yet.
i also didn't manage to make ref qualified accept functions, in particular i failed at generating a function space with the const& qualified accept_impl function. maybe there's some obvious idiocy that i'm not seeing?
conspired against by a confederacy of dunces.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2014-08-07 01:05:47
August 07 2014 01:02 GMT
#10157
While we're at the C++ topic, could you recommend a good book that would teach me C++11? I'm not a beginner in the world of programming but I'm not an expert either, so anything too advanced would just be bad. Basically, I don't want to learn old C++ stuff only to learn that C++11 or earlier version does it better. I have no experience in C++. I know what pointers are, and very basic stuff from C as well.
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
August 07 2014 02:56 GMT
#10158
On August 07 2014 10:02 darkness wrote:
While we're at the C++ topic, could you recommend a good book that would teach me C++11? I'm not a beginner in the world of programming but I'm not an expert either, so anything too advanced would just be bad. Basically, I don't want to learn old C++ stuff only to learn that C++11 or earlier version does it better. I have no experience in C++. I know what pointers are, and very basic stuff from C as well.


In general, learning a specific language unless you know you're going to be using for your work/projects is a terrible idea. It's a great idea if you have zero knowledge about programming and just want to figure out what it is, in which case languages that don't make you want to dip your face into boiling oil are a better option. Like Python!

You need to change your approach to have you view the field of computer science. It's like asking how to architect a house by learning how to use a hammer. Why do you want to learn programming? What are you going to do with it? Where do you see yourself with in down the road?

If you're seriously interested in computer science and not just programming, then you need to go much deeper than just C++. There's a whole world of mathematics, data structures, and algorithms that you should learn to give you a solid foundation. Then you need to dabble in fields to get some breadth - operating systems, video game programming, web programming, database design, artificial intelligence, machine learning, computer vision, etc... Once you have an idea as to what sub-field you actually care about, that's when you should pick and learn a language. If you're doing operating systems, learn C inside and out. If you're doing databases, learn SQL. If you're doing web, learn python, perl, javascript... etc.

If you don't care about computer science and just want to program, then figure out what you want to do with your programming and learn appropriate languages. Don't waste your time with C++. It has a very niche place in the programming world right now, it's huge, really ugly, and has a lot of unnecessarily confusing shit (i.e. why do templates have to solve the Halting Problem? I need a pointer, let me google the 87 types of smart/dynamic/static/shared/whateverthefuck type of pointer I need for 10 minutes because I'm scared of memory leaks...). Quite frankly the only non-legacy things I can think of that C++ is being used for today is probably video game programming.

TL:DR: Figure out what you want to do with programming before wasting your time with C++.

nunez
Profile Blog Joined February 2011
Norway4003 Posts
August 07 2014 08:17 GMT
#10159
I need a pointer, let me google the 87 types of smart/dynamic/static/shared/whateverthefuck type of pointer I need for 10 minutes because I'm scared of memory leaks...


you don't need a pointer, you need a bib. it seems when push comes to shove the gripe ppl have with cpp is that they are bad at it, and instead of honing their skills they cry and go for something easier. much like starcraft and the mobas.

cpp is at least top 5 popular programming language from what i can gather, and it will stay that way.

@darkness
i think "concurrency in action" was pretty consitent with using c++11 features, but i dunno tbh. there is a talk i linked earlier from scott meyers on x-value references which i though was a good start for understanding xvalue references. but maybe most important is to lock down move semantics, which is pretty sweet, and it makes RAII even better.
conspired against by a confederacy of dunces.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
August 07 2014 10:43 GMT
#10160
On August 07 2014 11:56 Abductedonut wrote:
Show nested quote +
On August 07 2014 10:02 darkness wrote:
While we're at the C++ topic, could you recommend a good book that would teach me C++11? I'm not a beginner in the world of programming but I'm not an expert either, so anything too advanced would just be bad. Basically, I don't want to learn old C++ stuff only to learn that C++11 or earlier version does it better. I have no experience in C++. I know what pointers are, and very basic stuff from C as well.


In general, learning a specific language unless you know you're going to be using for your work/projects is a terrible idea. It's a great idea if you have zero knowledge about programming and just want to figure out what it is, in which case languages that don't make you want to dip your face into boiling oil are a better option. Like Python!

You need to change your approach to have you view the field of computer science. It's like asking how to architect a house by learning how to use a hammer. Why do you want to learn programming? What are you going to do with it? Where do you see yourself with in down the road?

If you're seriously interested in computer science and not just programming, then you need to go much deeper than just C++. There's a whole world of mathematics, data structures, and algorithms that you should learn to give you a solid foundation. Then you need to dabble in fields to get some breadth - operating systems, video game programming, web programming, database design, artificial intelligence, machine learning, computer vision, etc... Once you have an idea as to what sub-field you actually care about, that's when you should pick and learn a language. If you're doing operating systems, learn C inside and out. If you're doing databases, learn SQL. If you're doing web, learn python, perl, javascript... etc.

If you don't care about computer science and just want to program, then figure out what you want to do with your programming and learn appropriate languages. Don't waste your time with C++. It has a very niche place in the programming world right now, it's huge, really ugly, and has a lot of unnecessarily confusing shit (i.e. why do templates have to solve the Halting Problem? I need a pointer, let me google the 87 types of smart/dynamic/static/shared/whateverthefuck type of pointer I need for 10 minutes because I'm scared of memory leaks...). Quite frankly the only non-legacy things I can think of that C++ is being used for today is probably video game programming.

TL:DR: Figure out what you want to do with programming before wasting your time with C++.



Hi, thanks but I already know what Computer Science is. I have a bachelor degree. I'm asking for books about C++ because I may actually need to learn it if I get hired. So once again, can anyone please recommend some C++11 book? I don't really want to learn old habits, so that's why I'm asking for C++11 right away.
Prev 1 506 507 508 509 510 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
WardiTV Mondays #62
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 181
SortOf 65
trigger 56
StarCraft: Brood War
Stork 788
Tasteless 197
Shine 147
NaDa 43
Bale 33
Icarus 9
ZergMaN 6
Dota 2
NeuroSwarm139
febbydoto29
League of Legends
JimRising 644
Other Games
summit1g11463
WinterStarcraft505
C9.Mang0338
ViBE137
Mew2King75
Organizations
Other Games
gamesdonequick927
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH106
• practicex 45
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki18
• Diggity4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1398
Upcoming Events
The PondCast
3h 52m
OSC
9h 52m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
17h 52m
Korean StarCraft League
1d 20h
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
[ Show More ]
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
5 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.