« first day (266 days earlier)      last day (4683 days later) » 
00:00 - 21:0021:00 - 23:00

9:12 PM
2
Q: The structure of std::forward

DeadMGI'm really curious- why does std::forward require an explicit template parameter? Couldn't it be simply template<typename T> T forward(T&& ref) { return ref; } I'd really like all the relevant detail, not simplifications, if possible.

 
@DeadMG would thread-local cache be sufficient? it would eliminate the need for locking
 
I asked a dupe, please vote to close
@StackedCrooked: But then you'd get two different std::vector<int> types if they were called from different threads
 
Awesome, thread-safe types :)
 
lol
well, I can't have std::vector<int> not being the same type as std::vector<int>
that would just be dumb
actually, you might be on to something
I could use a message-passing design
the problem with that is that I'd be passing messages and stuff for virtually every function call that needs to be thread safe
interesting idea
 
It's not clear to me what you are trying to achieve. I get you want to implement type equality by associating types with a numeric id?
 
9:18 PM
but then I'd have to deal with a mess of memory allocation and stuff, whereas with a lock then objects can live on the stack in fairly direct correlation to the written code
no
I want to implement type equality with referential equality
i.e., pointer comparison
because honestly, for arbitrary arguments, I can't really see anything else to do
the problem with that is that if you call std::vector<int> twice, it'd make two different types and the referential equality would fail
meaning that if I want concurrent compilation and referential type equality, then I need to concurrently memoize the function
 
Is this a thought experiment. Or are you planning on building it?
 
well
I don't want to start building it without a solid plan
I'm still unsure about how I'm going to implement quite a few things... mostly, how I'm going to output C++ and manage that
dealing with definitions and declarations could be a major bitch, even without templates and managing headers automatically
but I'd sure like to make an effort to it
 
9:33 PM
Perhaps BNF, yacc, bison can help here.
 
absolutely
 
Not too familiar with stuff like that though.
 
but then I'd have to have a solid plan as to the grammar, instead of how I'd like it to work
:P
 
If you manage to build it I'll probably use it.
 
well
 
9:36 PM
A nicer language that compiles to C++.
 
if I complete a version that can pre-process into C++, then I can also include some C++ headers too
allowing project migration, something D never had
and I can also grab some MSVC stuff like COM support, C convention support, x64 support, right off the bat
and __declspec(dllexport) and stuff
 
Almost like preprocessor then.
I've had some interest in the Felix programming language, but never tried it.
It's an ML-like language that compiles to C++.
 
never really used
 
you know about it?
 
I've heard of ML, somewhat
never really looked into it
 
9:41 PM
Neither have I, only indirectly by tinkering with Haskell.
 
not interested in Haskell, really
what can you do in Haskell that you can't in C++?
 
Some people think recursive data structures in Haskell are cool.
 
I think I don't like the language doing my work for me and I like to have explicit control of every operation
 
My day jobs for the last couple years have been split pretty evenly between haskell, F#, and C++
 
C programmers also use this argument, and so do assembly programmers.
 
9:45 PM
Practicing pure functional programming techniques in real FP languages is usually good practice for TMP in C++
 
that's not even remotely the same
 
Haskell does have this drawback that it makes reasoning about performance difficult.
 
@DeadMG You say that with.. what experience? ;-]
 
in C or assembler you have to control every operation of the CPU, whereas in C++ I control every semantic operation
 
Oh, disregard that, I mistook your reply as being towards me
 
9:46 PM
no prob
 
@DeadMG I like that about C++ also, and there doesn't seem to be any other language that allows this. (D excluded probably)
 
@StackedCrooked Ada95
 
@ildjarn Ada was on my mind, but I don't know enough about it.
Stepanov mentioned in an interview that C++ generics were inspired on Ada.
 
I did a handful of contracts for the USAF a few years ago, migrating code from Ada to Ada95 and C++, it was pretty comfortably close to the metal
 
honestly? I don't really care about close to the metal
I care about control
 
9:52 PM
@ildjarn Btw, Stepanov is an outspoken non-believer in functional programming.
 
the two are not the same
 
> There were some interesting ideas, but the research didn't lead to practical results because Tecton was functional. We believed Backus's idea that we should liberate programming from the von Neumann style, and we didn't want to have side effects. That limited our ability to handle very many algorithms that require the notion of state and side effects.
 
@StackedCrooked I bet he's never used haskell /shrug
 
@ildjarn Haskell solved some of the problems, but that's unlikely to change his mind.
 
honestly? I've got nothing against functional programming
it's just like OO programming- it has a place
the problem is, just like in OO programming, where you try to write your whole program rigidly to the exact same set of principles
then you end up with messes like Java
the difference is that since FP is older than OOP, I believe, they noticed the need for generic programming and flexibility sooner than OOP
 
9:55 PM
I like functional programming too. But if you restrict yourself to pure functional paradigm then you can't stay very close to the machine.
 
@DeadMG I'm not a FP diehard, I just find the mindset is good practice for TMP in C++
 
@ildjarn There is some incompatibility between FP and C++. For example FP programmer's will frown upon swap, while it is a very important concept in C++
 
@StackedCrooked I'm talking about template metaprogramming specifically
 
@StackedCrooked: That reminds me, I really don't like copy-and-swap and I think it might be a fail idiom
 
@ildjarn ok, C++ compile time programming is a form of FP
@DeadMG And I just started to like it.
 
10:02 PM
imagine in the simple case of std::string, assuming that we have a large string so no SSO
you're assigning one lvalue to another, but where the destination already has enough memory to hold the string
if you copy-and-swap, then you're making a heap allocation unnecessarily
you'd really need
 
@DeadMG true, but it's an optimization imo
not a general case
 
the same would be true of any type which holds a container
and I'm guessing that a lot of them do
 
It only matters for contiguous memory containers.
You can't do this optimization for set or list.
 
no, I disagree
you can always do that optimization for set or list
because the existing set or list has pre-allocated nodes
for a destination list or set of size N, you'd waste N heap allocations and de-allocations, if the source has a size of N or more
that's some serious wastage
re-using those heap allocations would be a critical optimization
for a contiguous memory containers, it'd at least be only one allocation
 
This is not very elegant and not very C++-like imo.
 
10:11 PM
no, no, no
C++ is about doing what you have to do and what's best for your current situation
that's it
re-using nodes is extremely C++- it's vastly more efficient for the same semantics
how is algorithmic optimization not C++?
 
But think of how the implementation now looks:
if (size() >= rhs.size()) {
    copy(rhs);
} else {... }
 
oh noes
 
Copy/swap looks much cleaner.
 
cleanliness is an arbitrary, subjective qualifier with no value whatsoever
just like purity and elegance and all the rest of that crap
 
It is subjective, but that doesn't mean it doesn't have value.
 
10:15 PM
Paul Graham rant inc
 
either an algorithm is performant, generic, whatever, or it isn't, and that's it
the only function of that string function is to copy the string, it doesn't have to be generic, so we can cut that need
and if it's more performant, then it's a performance win for no cost
what exact value do you think that cleanliness has? a warm fuzzy feeling when you read the source? fast, clear, optimized algorithms are the objective at hand
 
Copy/swap works very nicely when dealing with ref-counted resources. Recently I had to develop a C++ wrapper class around the Linux udev library. This library uses refcount mechanism for its resources. So in C++ with copy/swap you can implement it like this:
class Device {
    Device() {
        handle = udev_create();
    }

    Device(const Device & rhs) {
        udev_ref(device);
    }

    Device & operator=(Device rhs) : {
        swap(handle, rhs.handle);
    }

    ~Device() {
        udev_unref(handle);
    }

    udev_device_t * handle;
};
I think this is an example where copy/swap shines.
 
of course
 
Because a traditional assignment operator would first deallocate, potentially leading to unintended destruction. So you'd have to pay attention not to do this.
 
I'm not saying that copy & swap isn't great, or it isn't generic, or even in the most case, it isn't performant
but some generic algorithms have to be specialized
hey, my proposed string operator still uses copy & swap
just only if it's not optimizable
 
10:28 PM
You could compare with benchmarks. If differences are significant then you definitely have a point. I can't tell though.
 
well, you'd make a tremendous saving in the case of node-based structures like lists, maps, sets, and a fair saving in string/vector/queue/deque/stack
the only question is how often that operation genuinely occurs
the thing is, since there's no downside to it, then it's something for noting
 
10:42 PM
Self-assignment is of course much more expensive with copy/swap.
 
eh
self-assignment was shown to be so rare that checking for it was slower than being slow when it happened
some guys did some serious research and code-base checking, and it virtually never happened in reality
 
I mean, actually doing self-assigment is slower.
But that's a thought, not really relevant.
 
well
when I saw self-assignment checking operators, I was like, hey, that's smart
but, premature optimization, the root of all evil
 
self-assignment can cause bugs if not checked. Old-fashioned assignment is implemented as: { if (this != &other) { destroy() ; copy(other); } return *this; } . Not doing the check would lead to destruction of itself.
 
those weren't properly exception safe anyway
 
10:48 PM
indeed
 
copy-and-swap addresses those issues quite well enough
 
There was an attempt in Sweden to recognize filesharing as a religion. It failed.
 
lol
there was a Jedi religion in the UK
some people who hated the census decided to label themselves as Jedi
unfortunately, there's a legal loophole that officially recognizes any religion that has X many followers on the census
so for a while we had an official Jedi religion
 
00:00 - 21:0021:00 - 23:00

« first day (266 days earlier)      last day (4683 days later) »