« first day (195 days earlier)      last day (4755 days later) » 

5:00 PM
And MSVC doesn't warn about missing case statements by default, anyway.
 
@PiotrLegnica will the compiler complain about out of bound access of the array?
Oh, I get it. The length of the array will change.
I've been thinking that it may be nice to have syntax like this:

template<>
Meta<Foo, A>
{
const char * StringValue() { return "A"; }
};
 
I think it would complain, now I'm not so sure.
Eh, in any case, a switch with a missing case statement for the new enum value isn't any safer. It might not crash, but it'll give wrong result silently and that's worse.
 
@PiotrLegnica : Not if your the IT dept. You put in a request to fix a network issue and they say their network is fine and install a new harddrive on your machine. Except they have a fried image, so you have to uninstall and reinstall everything. Then you realize the MSI transaction log is fried to hell with no way to restore, and you simply reinstall the OS yourself and download all the software off the network.
 
@PiotrLegnica You can throw an exception if the code reaches the default case.
 
sbi
@StackedCrooked That should be static.
 
5:06 PM
@sbi Ah, you're right.
 
@PiotrLegnica : hmm... guess my cmpy is nearing end of life....
Nope. Philosophy is, if it works and we can bubble it, we'll never have to upgrade.
I hope they bubble their retirement home.
 
An OS without security updates is not worth keeping.
 
The Boost.Enum proposal seems nice:
BOOST_ENUM_VALUES(Level, const char*,
(Abort)("unrecoverable problem")
(Error)("recoverable problem")
(Alert)("unexpected behavior")
(Info) ("expected behavior")
(Trace)("normal flow of execution")
(Debug)("detailed object state listings")
)
Mentioned here: stackoverflow.com/questions/217549/… However, the download link seems broken..
 
Preferably one in the style of a caveman dwelling.... so that when they discover fire.... it can be on the cave headlines, chiseled into the wall.
My programming environment is running on XP.
And from VS 2005, an upgrade to VS2011 isn't a justifiable expense.
If 2005 works, why upgrade. You can still do your job right?
 
Well, you can upgrade compilers for free.
 
5:14 PM
I have MS Visual C++ 6.0 installed..... The icon looks like it was made for a Tandy.
They gave us a dam MS Office upgrade....
I'm running office 2007, and VS 2005.
Apparently, the secretary couldn't do her job without the "ribbon", yet I can do just fine with a stone axe.
 
5:46 PM
i reported this GCC bug. let's hope they fix it ASAP
1
Q: Why this output ?

Tretwick MarianHello,I have been trying to understand of this following C-program: #include <stdio.h> int arr[] = {1,2,3,4}; int count; int incr(){ return ++count; } int main(){ arr[count++]=incr(); printf("%d %d",count,arr[count]); return 0; } The program gives 1 2 as output,what I ...

 
@sbi What were you doing in American kitchens?
lulz
 
sbi
@TonyTheTiger Kitchen talk. What else?
 
@sbi wow that was quick
hmmm I find that new line for this room quite appropriate for me
 
sbi
@TonyTheTiger I happened to look at that window the very moment you posted that.
 
@sbi hahah funny :)
@sbi seems you got somewhat annoyed with Miss earlier?
 
sbi
5:54 PM
@TonyTheTiger Seems I wasn't the only one.
 
@sbi Yea, I know, I got annoyed with her earlier too, I've ignored her now, a bit too much
so what does the weekend bring for everyone?
 
Xeo
2 hours ago, by StackedCrooked
I find myself unable to be productive today.
Oh I can soooo relate to this today
Basically, I've been sleeping all day
 
@Xeo I've been relating to that for a while now :) LOL
@Xeo I mostly sleep at night though...
 
Xeo
Lately, I've been sleeping day and night..
 
@Xeo its called hibernation
 
Xeo
6:04 PM
@TonyTheTiger Don't remind me of hibernation. Putting my Debion VBox in hibernate sets my PC in hibernate too... because Vbox somehow takes up all RAM and CPU then
 
@Xeo get a better PC :P
 
Xeo
@TonyTheTiger That's not the issue!
 
@Xeo use another program then VBox then?
 
6:34 PM
Debion VBox is a bi... scuit
 
@Xeo You mean OS-level hibernate, or VBox's "save machine state"?
 
Simplest enum emulation that supports "conversion to string" that I can come up with:


#include <iostream>
#include <string>

#define Futile_EnumEntry(EntryName) static std::string EntryName = #EntryName

namespace RGB
{
Futile_EnumEntry(Red);
Futile_EnumEntry(Green);
Futile_EnumEntry(Blue);
}

int main()
{
std::cout << RGB::Red << ", " << RGB::Green << ", " << RGB::Blue << std::endl;
return 0;
}
^ Perhaps a bit silly. But it may prove useful :)
 
Xeo
@PiotrLegnica OS-level hibernate
 
sbi
@StackedCrooked Except that you can't switch over such enums.
 
@StackedCrooked I was thinking about those enums, and what do you think about external code generators?
 
6:39 PM
@sbi Hm.. good point.
 
@Xeo Try saving then. :P
 
@PiotrLegnica That would be not ideal, but if necessary, yes.
 
#define Futile_EnumEntry(EntryName, N) static int const EntryName = N; struct EntryName { static string value() { return #EntryName; }
 
@sbi Btw, that was FAST!
 
@sbi Would the case actually convert to int, such that he could return an int using an operator?
 
sbi
6:40 PM
@StackedCrooked Are you guys conspiring to tease me with that?
@Xaade I have a fatal parse error on that.
 
@sbi lol
 
I like code generators, I think they're cleaner than PP tricks.
 
defining the enum as XML and then using XSLT
 
@sbi : Add a operator = int on it that returns an int whenever the object is used in a situation that calls for an int. Would the switch... case X: request the object be an int, using your operator.
 
sbi
@PiotrLegnica Until you try to setup an automatic build system, and suddenly you need a whole arsenal of tools installed just to build the simplest toy project.
 
6:42 PM
Naw, enum can be in C++, parsing a simple subset is not that hard.
@sbi Well, I always integrate such tools with a build system, so it's not really visible.
 
as long as there are no templates and no functional casts, it seems doable
 
sbi
@Xaade Once you're at macros, what's wrong with making those EntryName identifiers integers, and add another const for the strings?
 
@JohannesSchaublitb That can't be right, can it? Using EntryName for both the int and the struct?
 
@StackedCrooked sure why not?
 
sbi
@Xaade Ah, @Johannes already did so.
 
6:44 PM
Yes
That's what I meant
 
EntryName::value() gets the string, and EntryName the int
 
@JohannesSchaublitb Today I Learned.
 
@JohannesSchaublitb However, I think would prefer to return the int via a static method also, seems more consistent.
 
9
Q: Use of the "memberspace" idiom?

Johannes Schaub - litbToday I learned about the C++ "memberspace" idiom, which roughly abuses a property of C++ that makes T::bar as well as T.bar work, when T is both a type and an object in some scope. struct A { struct Controls { /* put some typedefs/data/functions here */ } Controls; }; // Can be used a...

 
6:48 PM
@JohannesSchaublitb You finally have an answer to that question now?
 
i want to make it a community wiki question
but they don'T allow that anmyore. iguess im out of luck
i will never ever accept any answer t that question
because it's all opinion
 
sbi
@JohannesSchaublitb You flag for a mod asking to make it CW nowadays.
 
@StackedCrooked : #define Futile_EnumEntry(EntryName, N) struct EntryName { static string value() { return #EntryName; } static operator int() {return N; }}
 
Actually, forget my previous remark about return the int via a static method. Your suggestion works (really* well.
 
6:51 PM
There
Now it will work in a switch.
 
@Xaade Did you test it? Doesn't seem to compile for me.
Operator int must be nonstatic.
 
Operators T can be static?
 
hmm... guess not
that failed miserably
 
Now I'm wondering.... why can't unary operators be static..... :(
At least unary RHS should be allowed to be static.
 
sbi
6:54 PM
@Xaade What about this:
#define Futile_EnumEntry(EntryName, N) \\
    struct EntryName_type { \\
        static string name() { return #EntryName; } \\
        static operator int() {return N; } \\
    } EntryName;
 
I think it looks really nice now;

#include <iostream>
#include <string>


#define Futile_EnumEntry(EntryName, N) \
static int const EntryName = N; \
struct EntryName { \
static std::string ToString() { return #EntryName; } \
} // semi-colon must be typed when calling this macro


namespace RGB
{
Futile_EnumEntry(Red, 1);
Futile_EnumEntry(Green, 2);
Futile_EnumEntry(Blue, 3);
}


int main()
{
std::cout << RGB::Red << ", " << RGB::Green << ", " << RGB::Blue << std::endl;
std::cout << RGB::Red::ToString() << ", " << RGB::Green::ToString() << ", " << RGB::Blue::ToString() << std::endl;
 
@sbi That's what I did
 
That should probably be EntryName ## _type.
 
sbi
@PiotrLegnica Indeed. I typed in a hurry, and did not compile. Sorry.
 
@sbi @JohannesSchaublitb I guess the manual numbering can't be avoided?
 
6:56 PM
All that does is allow you to create a type.
 
sbi
However, the disadvantage of this is that now those values aren't of the same type anymore. Thus another failure.
 
They didn't have a type before... other than struct
 
sbi
@Xaade In enum Color { Red, Green, Blue } however, all values are of the same type.
 
But in a switch, it won't matter.
You're returning int, which is the same type
 
@sbi Yeah, but you can just use named methods instead of operator int . I don't really care about that bit of syntactic sugar.
 
sbi
6:57 PM
@Xaade No, but try passing them to the function that has the switch...
 
Derive from a base type?
Either way, now he has to instantiate instances, instead of them just being there.
 
sbi
@Xaade Polymorphic classes for enums?? Ugh.
 
@sbi : Well, forgive me for trying.
I'd be happier just creating the enum and referencing a map
 
@sbi Doesn't need to have virtual methods.
 
Actually the base class would be empty, and abstract.
It would just be a polymorphic placeholder.
Aight, I'm out.... Peace!!!
 
7:00 PM
@sbi all values have type int const
 
Actually.... @Johannes is right, you wouldn't pass in the structs, you'd pass in the ints......
No need for a base class.
 
only bad thing IMO is that it's not an rvalue
you can instead say enum { ... } but then you have them have different types
the only way to declare an int rvalue AFAIK is by use of a non-type template parameter
 
sbi
@Xaade Forgive me for pointing out when you failed. :)
@Xaade But then you can't get at their strings anymore.
 
in an unproductive phase, I usually stop programming and start writing documentation
@Xaade what about static int get_init() { static int val; return val++; }. then init them by get_init()
will be unique for every TU.
hm wait, that will fail if you include the enum by header into multiple TUs -.-
 
sbi
@JohannesSchaublitb I used to be in a company where, in an unproductive phase, you'd go to play table tennis or pool. Incidentally, the same company also provides a cooked meal for free to everybody.
 
7:07 PM
i see
i "worked" as a student for a short time for one big company too. good meal, too :)
+ table tennis :)
 
sbi
Mine was a small company, though. About 25 employees, half of which were developers.
 
sbi
@JohannesSchaublitb No, a small one!
 
Btw, simplest workaround for adding a common typename in order to enable a switch:
namespace RGB {
typedef int Instance;
Futile_EnumEntry(Red, 1);
Futile_EnumEntry(Green, 2);
Futile_EnumEntry(Blue, 3);
}

void TestSwitch(RGB::Instance rgb) {
switch (rgb) {
case RGB::Red: { std::cout << "It's red." << std::endl; }
default: { std::cout << "It's not red." << std::endl; }
}
}

Seems, I'm in the mood for simplistic solutions today :)
Non unique type though.. Not sure if that is problematic.
 
7:17 PM
that one should work
hm wait, it couldn't be used as a switch if done that way :(
 
@JohannesSchaublitb Nice! It's very nice that each enum restarts the count at 0.
@JohannesSchaublitb I wouldn't rename the namespace, just leave it as is, so I am free to use RGB::Blue or Blue (intellisense advantage).
 
Next step: variadic macro: ENUM(RGB, Red, Green, Blue)
Just kidding :D
 
7:42 PM
@JohannesSchaublitb It's also an expandable enumeration. Which is nice.
 
sbi
@StackedCrooked That would actually make it much easier. One macro instead of three.
 
@JohannesSchaublitb you're really smart, but probably not smart enough to implement it with variadic macros. Pity :(
( @sbi do you think this reverse psychology will work?)
 
I'm trying with Boost.PP, but I suck at this, so don't hold your breath. :P
 
I'll give it a try myself
 
7:49 PM
@StackedCrooked yes i'm a stupid troll :(
 
@JohannesSchaublitb I'm guessing you're immune to "reverse psychology". Damn.
 
sbi
@StackedCrooked I'm actually being serious.
 
@StackedCrooked yep I am
 
@sbi Yeah, I think also it would be a great improvement. I'm looking at the possibilities.
 
3 enum values is enough for everyone.
<3 for the real artworkers
 
7:51 PM
#define FOO(fmt, ...) printf(fmt, ##__VA_ARGS__)
 
The VA_ARGS is converted to var_args, which isn't usable.
If there would be some way to expand at macro-level.
Probably not.
 
sbi
The problem with enumy strings is that, ideally, you'd want the enum type itself, plus some additional magic for getting at the strings, but you can't define those strings in your enums. So you would need to actually iterate twice over those enum values, and for that they'd best be in one sequence.
 
ever tried fusion
 
@JohannesSchaublitb VMWare Fusion?
 
7:52 PM
6
A: Print information in "test mode" but not in "normal execution"

Johannes Schaub - litbI try to avoid using var-arg c-style functions for two main reasons: They are not type-safe, can't use operator<< They don't recognize when too few or many arguments were provided I've made a way that works using boost::fusion, which is given arguments in a type-safe way. It iterates ov...

 
#define ENUM(Name, Memb) \
	namespace enum_ ## Name { \
		typedef struct t_ ## enum_ ## N tag_type_; \
		BOOST_PP_SEQ_FOR_EACH(ENUM_MEMB, BOOST_PP_EMPTY, Memb) \
	} using namespace enum_ ## Name
#define ENUM_MEMB(R, Aux, El) \
	static int const El = init_get<tag_type_>(); \
	struct El { static char const *name() { return BOOST_PP_STRINGIZE(El); } };
Then it's ENUM(Test, (Hello)(Folks));
 
it seems there is no way to get a compile time constant init :( not even in c++0x
hmm
 
@PiotrLegnica That looks interesting. Have you got a working sample?
This would probably be very easy with m4. Pity is isn't as standard as the CPP.
 
@StackedCrooked It's port of @Johannes code, so ideone.com/XzUpU
I'm pretty sure it can still be made better, though.
 
Nothing can be done by implementing the comma operator I guess?
 
8:07 PM
also have you considered nedbatchelder.com/code/cog :)
 
#define ENUM(Name, N, ...) \
	namespace enum_ ## Name { \
		typedef struct t_ ## enum_ ## N tag_type_; \
		BOOST_PP_SEQ_FOR_EACH( \
			ENUM_MEMB, BOOST_PP_EMPTY, \
			BOOST_PP_TUPLE_TO_SEQ(N, (__VA_ARGS__)) \
		) \
	} using namespace enum_ ## Name

ENUM(Test, 2, Hello, Folks);
With varargs, but requires explicit size.
 
@PiotrLegnica That's quite nice @PiotrLegnica ! ...Does it work?
 
@StackedCrooked It does.
At least on MSVC2010.
 
@JohannesSchaublitb Not really..
 
lol
@PiotrLegnica what is that "N" for? will the inits now be compile time constant?
i don't understand that macro foo
 
8:13 PM
No, but hm, they could be.
 
yeah, i think you could put together 1+1+1+1+1+1+1+1...+1 and then let it evaluate :)
 
@PiotrLegnica Ok, also works on Mac gcc (4.2.1).
 
but with boost.pp you should be able to refer to the last enum value and just add +1 or something
 
Are you aiming to make it so that this would work?
template<int n>
class CompileTime { };

CompileTime<RGB::Red> test;
Because that doesn't work in any solution yet.
@JohannesSchaublitb Or do I misunderstand when you ask if "inits are compile time constant"?
 
no you don't
 
8:23 PM
I see. Cool.
 
I think I've got it.
#define ENUM(Name, N, ...) \
	namespace enum_ ## Name { \
		BOOST_PP_SEQ_ELEM(1, \
			BOOST_PP_LIST_FOLD_LEFT( \
				ENUM_MEMB, (0)(;), BOOST_PP_TUPLE_TO_LIST(N, (__VA_ARGS__)) \
			) \
		) \
	} using namespace enum_ ## Name
#define ENUM_MEMB_(St, El) \
	static int const El = St; \
	struct El { static char const *name() { return BOOST_PP_STRINGIZE(El); } };

#define ENUM_MEMB(_, St, El) \
	(BOOST_PP_ADD(BOOST_PP_SEQ_ELEM(0, St), 1))(BOOST_PP_CAT(ENUM_MEMB_(BOOST_PP_SEQ_ELEM(0, St), El), BOOST_PP_SEQ_ELEM(1, St)))
 
this macro foo is certainly way over my head
lol
 
It produces ;; at the end of the last struct, though, MSVC doesn't complain, dunno about others.
Initial state can be (0)() to eliminate ;;, but then I get a warning about macro arguments.
ENUM_MEMB with some whitespace.
#define ENUM_MEMB(_, St, El) \
	( \
		BOOST_PP_ADD( \
			BOOST_PP_SEQ_ELEM(0, St), 1 \
		) \
	)( \
		BOOST_PP_CAT( \
			ENUM_MEMB_(BOOST_PP_SEQ_ELEM(0, St), El), \
			BOOST_PP_SEQ_ELEM(1, St) \
		) \
	)
 
i think we can modify the state by always adding one function overload
` namespace E {
/* start with 1 */
N<1> C(N<1>);
}

namespace E {
/* increment to 2 */
N<sizeof(C())+1> C(N<sizeof(C())+1>);
}
`
 
@PiotrLegnica do you have a link to the working sample?
 
8:33 PM
the problem seems to be to find the last added overload quickly
 
@StackedCrooked ideone.com/eD11k
 
@PiotrLegnica Lol #define ;; ; doesn't work!
@PiotrLegnica gcc complains though: Enum.h:29:1: error: pasting ";" and ";" does not give a valid preprocessing token
 
in c++0x it would be not difficult
 
@StackedCrooked Try changing initial state to (0)() (in ENUM, second argument to the fold).
 
i think. with decltype one can do something
 
8:39 PM
@PiotrLegnica

main.cpp:29:1: error: pasting ";" and "static" does not give a valid preprocessing token
main.cpp:29:1: error: pasting ";" and "static" does not give a valid preprocessing token
main.cpp:29:1: error: pasting ";" and "static" does not give a valid preprocessing token
main.cpp:29:1: error: pasting ";" and "static" does not give a valid preprocessing token
Same error remains.
 
Hm.
Oh, I think I know how to fix it.
#define ENUM_MEMB(_, St, El) \
	( \
		BOOST_PP_ADD( \
			BOOST_PP_SEQ_ELEM(0, St), 1 \
		) \
	)( \
		ENUM_MEMB_(BOOST_PP_SEQ_ELEM(0, St), El) \
		BOOST_PP_SEQ_ELEM(1, St) \
	)

#define ENUM(Name, N, ...) \
	namespace enum_ ## Name { \
		BOOST_PP_SEQ_ELEM(1, \
			BOOST_PP_LIST_FOLD_LEFT( \
				ENUM_MEMB, (0)(struct dummyenumtypetostopwarnings_ ## Name;), BOOST_PP_TUPLE_TO_LIST(N, (__VA_ARGS__)) \
			) \
		) \
	} using namespace enum_ ## Name
There, works on both MSVC and g++ without warnings.
(gcc 4.4.0)
 
Oh, wow. I'm not totally failing with pointers. That's new and interesting.
 
@StackedCrooked ^
 
@PiotrLegnica Err, yes?
Ah I see.
 
Though that type is probably not needed, gcc doesn't complain about ;; either.
 
8:50 PM
@PiotrLegnica Yep, it works here too.
Cool, and it can be used as a compile-time constant as well..
 
9:10 PM
Is that for turning enums into strings? (I missed the whole thing :))
 
I overcomplicated it, it can be much simpler.
 
9:30 PM
Hi all, I just uploaded the wrong project to repository in subversion. What's the best way to undo this so I get the rpeository empty again? Thanks for response
 
9:40 PM
@JohnMerlino If you want the repository completely empty, I think the answer is a little obvious.
 
@Potatoswatter svn remove?
 
@JohnMerlino Blow away the repository and start over.
 
Can't because this is in a piece of software called jira. it doesnt jst let you delete repistory. I want to delete everything under trunk.
 
possibly quick rep for someone whose brain hasnt melted: stackoverflow.com/questions/5837693/…
 
Or a completely different idea. I think I like this one (except for that StringToEnum, maybe). I think I like Boost.PP.
 
9:44 PM
under trunk I have one directory called rail. I want to delete rail directory and everything under it.
svn remove? svn delete? Im not sure what is best approach for this.
 
Then remove it. You can't edit history, unless you can modify repo directly (recreate with svnfilter, or whatever that was called).
 
So if I use svn remove, svn isnt going to preserve a hidden .svn file and give me conflict down the road?
 
You're using SVN, you're going to get conflicts anyway, sooner or later. :P
 
I have no choice in the matter
I just need the ebst solution for right now
I guess I am going to do an svn delete to every file then
 
Easy rep if you know what you're doing with pointers: stackoverflow.com/questions/5837816/…
 
10:20 PM
> JSONx is an IBM® standard format to represent JSON as XML. JSONx conversion rules specify how a DataPower® service converts a JSON structure to JSONx (XML).
 
Xeo
10:40 PM
@PiotrLegnica What?
 
@Xeo Exactly.
 
@PiotrLegnica Nope, turns out we need it as JSON after all. Need an Oracle product to encapsulate it back.
 
11:19 PM
i think this should work:
dunno why it doesn't work
 
11:48 PM
@PiotrLegnica I found a way to automatically deduce the number of arguments in your code: stacked-crooked.googlecode.com/svn/trunk/PlayGround/…
 
@StackedCrooked I'm actually going crazy, and librarising it.
 
@PiotrLegnica :)
Me too.
 
I've added ENUM_STR, ENUM_VAL and ENUM_STR_VAL for customising strings and values.
 
When writing functions for converting enum to string. Should you choose unique names for each function like "ColorToString", "RequestTypeToString", ... Or is it better to give them all the same name "ToString(..)" and overload by enum type?
 

« first day (195 days earlier)      last day (4755 days later) »