« first day (281 days earlier)      last day (4894 days later) » 
00:00 - 17:0017:00 - 20:00

00:45
0
Q: code guards fail and template from string literal

wisoI know the only way to pass a string literal as template argument is to declare it before: file a.h #ifndef A_H #define A_H #include <string> char EL[] = "el"; template<char* name> struct myclass { std::string get_name() { return name; } }; typedef myclass<EL> myclass_e...

Does anyone have any opinions on using char* as a template parameter?
01:03
I've been doing that a lot these past few days (const char* to be exact).
@Kerrek I'm checking for a reference but you are incorrect; not just integral types are allowed as non-type parameter.
Yeah you are. I'm writing a big-ish answer to settle all this.
@LucDanton In C++98, too? GCC specifically tells me "only integral and enum types".
I looked it up for C++03 but I assume it's the same.
Also GCC warnings are really obscure in this area, at least from my experience.
Ironically, while char* is an acceptable non-type parameter, what the OP wants to do is forbidden. Yes it is.
01:33
@KerrekSB I've written an answer
Sigh, okay. Please don't flame me, but there's absolutely no one in the java room. Is anyone here familiar with Java, and willing to forgive my lack of chat room etiquette?
I've got a relatively simple question about setting an enum value
You can edit your message.
I totally knew that
The name of the room is also not relevant; any kind of topic can be discussed here. What's frowned upon is drive-by question dropping.
No idea if I can help you, I don't deal with Java very often.
ahh, well then in that case I will ask a question, and then lurk. I can answer questions about other languages
01:36
@LucDanton Nice. But I can't get it to work. Let me try one more time.
Basically I've got an enum that represents a menu choice, taken from the console
so the user inputs an int
and I need to set the enum instance to the correct value
the problem is that I can't find any enum setters in java other than assignment
@KerrekSB Oh god I did all my tests in C++0x mode, let me double-check that.
and I could do a switch statement on the int input, but there has to be a better way
@Eric_H What are you using if not assignment? A parsing function?
well, I was hoping to be able to set the value of my enum instance, using the int input to get the ordinal value
01:39
@KerrekSB Heh it still passes. Phew.
@Eric_H What happens when casting?
cannot convert
@LucDanton Ahh. I was trying to be too clever. It works if the template has a get_name member function.
coming from C++ and C#, this seems like it should be so simple
But it doesn't work if I want the template to have a const member.
I think the problem is that in java, enums are classes
01:40
@KerrekSB I used an empty type tbh.
instead of : C# - (int)myEnum, you use Java - myEnum.getValue()
I guess I can just add a method to the enum to allow for it
that's probably the Java Way
Apparently that's a feature, yet.
...I could have just searched "cast enum to int"
and saved you the trouble. I'm sorry, I didn't think about using that search phrase
No problem. That's exactly what the chat is for: when you're not sure something should be a question on the main site.
In turn it means that 'go ask on SO' is a valid answer to some questions that are asked here.
that's a good point
...you can index it like an array, apparently. I just gave this a shot:
01:44
@LucDanton How so?
MyEnum value = MyEnum.values()[ordinal]
and that worked.
weiiird
@LucDanton Oh, you mean you're not exposing the template value at all?
@KerrekSB No member or anything. I just checked that typedef whatever<array> stuff; compiled.
@KerrekSB Yeah, plus you can 'extract' it out of the template since it's part of the type: template<typename T> struct name; template<template<char*> class Named, char* Name> struct name<Named<Name>> { static constexpr auto value = Name; };
Which is something I wrote not long ago heh.
Yeah, to expose the value, you need constexpr,
but to use pointers, you must have extern linkage
The intersection of extern linkage and constexpr is pretty restricting
Well that's achievable isn't it? I just used constexpr for clarity/convenience.
Let me try.
01:48
Well, you need to put the value of the constexpr into each TU, so you can't have one in a global typedef
Static members of a template get a free pass.
Members of a template never end up in a source file.
You do have to define them out of line.
Yeah compiles fine for me.
(Not in C++0x mode, not that it changes anything.)
@KerrekSB What's your problem exactly?
@LucDanton How do you define the static member?
template<
    template<const char*> class Named
    , const char* Name
>
const char* name<Named<Name> >::value = Name;
I get template parameter ‘S’ of type ‘const char*’ is not allowed in an integral constant expression because it is not of integral or enumeration type and invalid in-class initialisation of static data member of non-integral type ‘const char*’
Yeah, it must be defined out of class.
In-class definitions of static members are only allowed for const and integral types.
Oh wait I'm repeating what the warning message is saying.
The in class declaration is simply const char* value; if you're wondering.
01:59
Hmm. Now it works. I don't know what I was doing earlier...
Time for a total rewrite of the answer, I suppose, or I could just delete it
Ah, it's strange, if I say template<char*>, then I cannot pass a const char[].
No, wait. I'm saying template<const char*>, but I have to pass a char[]
Weird
Ah, const char A[] = "abc"; seems to have static linkage, but extern const char A[] = "abc"; works
Yep.
A top-level const T t = ... declaration has implicitly internal linkage.
This is how const int the_answer = 42; is allowed to reside in headers.
Ah, that explains a lot. But why can I pass a char* to a const char * template?
I'll check but that paragraph 5 probably allows it
Maybe template parameters have no cv qualifiers?
Though I wonder what happens if you say char EL[] = "el"; EL[0] = 'a';
02:15
> for a non-type template-parameter of type pointer to object, qualification conversions (4.4) and the array-to-pointer conversion (4.2) are applied.
@KerrekSB I'd assume nothing happens, since that assignment will happen at runtime.
(Oh, that actually works as expected -- it's the pointer that's the argument)
@LucDanton Very nice
Why not add that to the answer?
It's already that long -- the paragraph is mentioned for the more inquisitive.
Well, that was instructive. Why would one want char-pointers as template arguments, though?
I mean, what's a useful application for that?
As I mentioned, I've been using them these past few days.
In my case it's poor man's reflection.
You can't specialize on them, though
02:20
e.g. I can declare struct position: named::tuple<named::field<x, int>, named::field<y, int>> {};
Then I can pass that type to my lua class and it converts from a Lua table to a position.
So do you store a bunch of string constants?
Yes, unfortunately.
I see
Interesting.
As I understand it there's a proposition to allow string literals.
For the record in the above x would be defined with DEFINE_NAME(x);
with #define DEFINE_NAME(name) extern const char name[] = #name
yeah, that helps
02:22
Silly GCC requires the extern when it shouldn't.
I'm not so sure if constexpr would be allowed though.
I don't suppose any of you gents have any game development experience?
Well, I guess I figured that since you'd be using a preprocessor anyway, you could just hard-code the string literal into the class definition with a preprocessor macro. No need to go the extra way with the pointer
I don't need help with anything, just curious
@Eric_H I can't say I have.
@LucDanton I'm using game dev to learn Java, and I'm stuck between building an OOP framework or a compositional one
02:24
@KerrekSB Okay, now write me the function that converts Lua tables to my types :)
constexpr has been very problematic, as I said. You can't declare it on one place and define it in another
Err.... search and replace? :-)
so I'm just looking for input
No you don't get it.
It's generic.
I don't deal with lua tables. I thought there should be a sensible C++ wrapper library that hides all this
I can start a new TU and write struct bleh: named::tuple... and presto it can be converted.
02:25
Yes yes, I see.That sounds pretty convenient
It's not impossible to do it your way but I don't think it's that convenient.
For the record I do use Luabind though (which is one such wrapper).
@LucDanton You mean a macro would be less convenient?
How would you do it? struct position { DEFINE_NAMED_FIELD(x, int); ... };?
No, a big #define that writes out the entire struct
variadic
recursive
Use Boost.PP? DEFINE_NAMED_DATA( position, ((int)(x)...) )
02:27
Perhaps
I considered that but I can't say I'm fond of it.
(Interesting. Never heard of PP. Coming to think of it, I should have expected it to exist.)
It's quite a big investment to learn in one go.
I can imagine
That's Boost.Preprocessor btw, just in case.
02:28
yeah
Just found it
It's used for e.g. generating n-ary overloads.
Anyway, I got to go. Thanks a lot for sorting out my mess!
@LucDanton , is the debate between compositional frameworks and inheritence frameworks a common one outside of game dev?

Meaning, have you dealt with it before?
I don't think it's common outside the Java world tbh.
Does compositional mean dependency injection?
Or object composition?
02:31
basically, instead of having an Entity superclass, from which all rendered or collideable object derive, you use Entities as named bags for components
and the components process the logic
so your entity inheritence structure is completely flat
unique entities are defined by unique combinations of components
(if that's what Object composition means, I apologize)
Object composition would how to implement what you describe and where it got the name I suspect.
ahh
man, University was embarrassingly inept at communicating commonly-used terms
Well the debate of what you describe probably exists elsewhere but only for frameworks/languages that are very, very OOP-oriented.
@EricH Don't beat yourself over it, I'm pretty sure I've seen that term used as you did.
i.e. compositional framework.
that makes sense, as the downside of the inheritence structure (bloat), only really makes itself felt when you're in a "pure" OOP language
and the worst part is that this homework assignment I'm working on shows off this terrible bloat. My professor offered an inheritence structure that... it's bad.

I'm getting the same thing done with one class and an enum
It's funny, now that I really understand OOP, my fervor for forcing 'pure' OOP paradigms on every problem has really died off
I hope that's a sign of growth as a developer
Tree-like type hierarchy are not that wield to use indeed.
02:37
Well, for instance, the framework I've been using for my game (which is still a pretty simple game) requires everything rendered to be an entity.

Thus, the entity superclass sits at around 1.25KLOCs
@Eric_H The way I see it it's the cycle of culture shock.
I think that an obsession with 'elegant' code exacerbates the issue - at least in my case
in the past, on projects that usually didn't get finished, I'd code something, and then go "hmm, I bet that's not best practices for OOP"
I'm very thankful that my first language was c++. It helps to fight the urge to "just throw it in a class!"
I definitely think that everyone should code first in a native language
I'm not sure native/non-native is a crucial difference.
I mean in terms of garbage collection and understanding the back end of pointers
If 'native' doesn't imply that, then I again apologize for misuse of terminology
Native usually means it compiles down to binary.
Alternatives are usually interpreted languages and JIT/byte-code/VM languages (it's more of a spectrum than categories).
02:44
I guess, then, I should just say 'start in a language without automated GC'
that more aptly communicates what I meant
yeah, one thing that's pretty uncomfortable to me about Java is that I reeeally don't understand the back end
for example, I've got a demo of my game running locally, but I just keep running into errors when I try to create an executable or webstart
It's important to distinguish the language and its constructs from its implementation(s).
and it's got to be because I don't understand how the VM works. I understand JIT pretty intimately, and c++ is easy to understand, but JVM... no
you're absolutely right
conceptually they're decoupled
I forgot how educational it could be to just hang out in a dev chatroom
speaking of, it seems strange to me that these chatrooms are so empty, when there are so many SO users
Lounge<C++> is quite populated at the right times.
That is, when compared to the other rooms. It's still nothing compared to the main site.
well, seeing as how I'm writing exactly nothing in c++ right now, it's nice that this IS a lounge
every time I look at the Java room, it says "last message Xd ago"
and it's usually "is anyone here?"
 
4 hours later…
06:49
hello
 
2 hours later…
08:32
hi all
im having an interest in Augmented reality...can anyone tell me how to implement logic for interacting virtual objects? ex: change a property of an object when another object is near etc.
user457812
Magnets. Thousands of magnets.
08:49
Hi
all rooms are sleeping I think so
:( yeah. sleepin.....
I am not C++ developer
09:52
hi
what's that web-based tool for making quick UI mockups? named after some vegetable or something
it's not asparagus...
pretty sure there's a q in it
ah, balsamiq! Not quite a vegetable then
hi
my grammar, it's so hideously, unbelievably ambiguous
identifier ( identifier ) ; // function call
identifier ( identifier ) identifier; // variable definition
identifier ( identifier ) { statements; } // function definition
you should disambiguate it then
10:01
well, I considered a kind of typename and function malarky
but I figure that instead, I'm just going to parse it backwards
they only look very ambiguous from the front :P
Is there a theme where good C++ programmers have to represent themself as animals @sbi @DeadMG @CatPlusPlus
not intentionally
How do you cut the line like you did with good?
sbi
sbi
@Raynos What?
@sbi you are a gorilla.
10:11
---strike---
sbi
sbi
@Raynos That gorilla avatar is just a disguise. Actually I'm a bonobo.
2
yes, we have already noticed that a lot of us use animal avatars
it's just coincidence
I'm a banana!
sbi
sbi
@CatPlusPlus Cannot be. You are more intelligent. Well, some, anyway.
It's a Rejected reference, tsk tsk.
10:18
there's no way I'm clicking that video
I am :D
It's a stickman showered in blood. How can you not click
blood not really my thing
stickmen aren't really my thing
also for the record, my penguin isn't part of some larger theme either. Been using it for a couple of years because a friend drew it for me and it looks cool :)
I'm using mine since about 2009.
sbi
sbi
@Raynos That's because you don't know the @Cat as well as we do.
10:25
You cannot not know Rejected.
sbi
sbi
@CatPlusPlus Actually I remember you having a different avatar until a few months ago.
You will watch it, sooner or later.
sbi
sbi
@jalf A guy from the upper parts of the northern hemisphere using a penguin. I always wondered about that.
@CatPlusPlus I'm old enough to know rejection way better than you ever could.
@sbi I don't really remember. Maybe I haven't set it as the gravatar then yet.
sbi
sbi
@CatPlusPlus I distinctively remember you changing your user name and using this avatar. That's been a few months ago.
Anyway, I'm going to spend the rest of the Sunday in the garden with the kids. See you later!
10:28
Oh, the name I've changed, but the avatar predates that.
I think.
I'm not good with past, it's all timey wimey.
@sbi the friend who made it is australian though. She was just doodling little sketches for a bunch of us, and asked what I wanted.. "... bwuuh... I dunno.. A penguin?"
Hello everyone. I have a quick question. How do you put links in a comment?
[title](link)
@CatPlusPlus Thanks! :) I thought it was something similar and tried (title)[link] which didn't work
There is 'help' link next to the textarea. :P
10:37
@CatPlusPlus There is? Never noticed it. I'll check it out
10:53
@jalf I always thought it was a snowman
This is the cropped version. The original had a little '<- penguin' note as well, to clear up any doubts, but that made it too tall to fit anywhere
lol
 
2 hours later…
12:59
@DeadMG I like the idea of a function keyword.
Just as I like the idea of a var keyword.
Makes parsing easier for humans and compilers.
Yeah, you don't have to suspect everything of being a function declaration, hint hint.
lol
I don't have function declarations, so no problem :P
besides, I think that my backwards parser can cope just fine without them
13:29
hi
he looks like the facebook guy
hammar, Norway
11.3k 2 19 43
 
3 hours later…
16:23
Whats wrong with norway?
the bombing and massive shooting that went on there?
like, nearly a hundred people dead kind of thing?
that's been all over the news for days?
Oh that
Yeah I remember that
Don't you think learning C++ first is like teaching a child to swim by dropping him in the middle of the pacific?
If he can make it to the coast he's a legendary swimmer, the only other option is to drown
@Raynos yea that describes the process quite well
no
it would be more like dropping him on a beach in the pacific- he can start slow and then swim as far as he damn well wants to
Really?
I guess so.
16:27
yes really
C++ isn't dropping anyone in at the deep-end- that would be poor tutorials and introductory material
Are there tools for easily writing applications in C++ ?
Visual Studio?
getting applications with working IO is a lot easier in more forgiven languages like python
I find it pretty easy
Your not 13, you have software development experience
16:29
no, I actually don't
I'm a student, never wrote any software in my life except mods for some game
and that wasn't even in C++
but more to the point
you're pretty good anyways, @DeadMG
I don't know what the hell you're talking about with more forgiving languages
what could possibly go wrong with int main() { std::string input; std::cin >> input; }?
@Tony: That's because I'm a certifiable genius :P
@DeadMG what is >>
@DeadMG yea, and probably also because you spend a lot of time doing it and learning new things :)
@Raynos: You don't know how to use the C++ Standard library?
16:31
@Raynos it's a streaming operator
how could you possibly even try to form an opinion on how forgiving C++ is if you have never seen C++ "Hello World"?
No I'm pointing out that the concepts behind >> are non-trivial to explain to a 13 year old
that puts inputinto cout
and cout writes to the console
whoops :P
@Raynos yea I know how that feels, I tried to learn C++ at that age :P
16:32
I just think C++ gets you to bogged in the machine details
@Raynos: Sure, there's lots going on - but you don't have to deal with it right off
You should be able to treat the machine as a black box when your learning
"cin >> variable reads input from console into variable". Done.
I guess my learning style isnt compatible
I would get stuck in the details too quickly
and I never dealt with any machine details in C++, that's what the Standard library is for :P
16:33
@DeadMG but >> is used with cout, not cin
because I learn depth first
not breadth first
But you may have a point
My opinion that C++ is overly hard might be biased based on poor teaching experience
but C++ shouldn't be learnt that way
that's why I was talking about sucky intro material
else you might as well learn asm first
the wrong way to go is learning "C with Classes" first
stick with the Standard library for a nice long time and you'll do fine
16:34
yea I agree with that
and first understand the basics of programming, you know, like int, float, class, object, etc
that's not even language dependent
is Cplusplus.com a bad website?
unless you're into functional programming, then some of these concepts aren't of help
I've heard many bad things about it
but never experienced any problems
but then I never used it
for learning C++ you need to buy a good book
I use MSDN as my documentation source
16:35
@TonyTheTiger effective C++ ?
like Programming Principles and Practices using C++ by Bjarne Stroustroup
that's the one I learnt it from :)
very easy and understandable, and not too much hard scientific english
@DeadMG you're an exception :P
yes, I am a genius
you take a lot of pride in your genius eh
but you know, if you aspire and work hard, you can be like me
hehe
can you give some of your genius to me ?
16:37
what else would I have to be proud of?
I'm a student so no education finished, no job, no family
you should be proud of it :)
it's very impressive :)
oh I know :P
I wish I was still a student
being a student is great
so much to learn, that I didn't take the opportunity to learn when I was at school, lol
16:39
university sucks
the lecturer goes "Hey guise, here's the theory of Bayesian Belief Networks"
at least you're enjoying what you do in your free time
"By the way, we don't actually build any or anything like that, that's way too useful for us, we'll just examine you on the theory. Have fun!"
true
lol, sounds like uni to me
theory and no practice
@DeadMG is that compsci ?
yes
16:40
Theory is fun :(
I do theory all day.
cause you might find it useful if you do it in practice, so let's stick to theory so it comes across as boring and not useful
I'm not a theory guy
havnt written any code since yesterday
16:40
I like ideas, I like to make things happen
doing something and not making something happen is thoroughly worthless
why bother knowing what a Bayesian Belief Network is if you can't make one?
true
>A Bayesian network, belief network or directed acyclic graphical model is a probabilistic graphical model that represents a set of random variables and their conditional dependencies via a directed acyclic graph (DAG)
For example, a Bayesian network could represent the probabilistic relationships between diseases and symptoms. Given symptoms, the network can be used to compute the probabilities of the presence of various diseases.
@DeadMG because when you need a BBN you can make one
knowing the theory of a BBN does not show that you can make one
16:43
It's about expanding your toolset so you when given a problem you can use the most specific and applicable tool to solve the problem
The alternative is to do everything in C++
that can work for me
at least you'd actually do things
it may involve a lot of wheel reinvention though
how is that true?
passing a course about BBNs should involve proving that you can create a BBN
isnt that what the labs/coursework do?
16:49
:(
But then all the people who cant program complain
"the hardest part" of our course is the coursework
they just say "Just do it in C"
if you can't program, then you shouldn't be passing a CS degree
then all the people who dont know C complain
@DeadMG thats a problem
How confident are you in your C++ skills?
yeah, it is a problem
it's a problem because too many people pass CS courses who can't program
confident enough to have them examined
I'd wager 95% with a CS degree don't have the skills you have in C++ in any language of choice
I think that's a real problem for people who hire people with CS degrees
16:51
That's just how it works :\
and something that universities should address
We have some skills but not enough
CS graduates have basic programming skills
But throw CS grads in the deep end and your get shit code
00:00 - 17:0017:00 - 20:00

« first day (281 days earlier)      last day (4894 days later) »