« first day (439 days earlier)      last day (4525 days later) » 

Ell
7:03 PM
cya
okay now I need help with actuall c++
*actual
Is anyone here btw? I hope I'm not talking to myself o.O
o.O
well anyway
I have a structure like so
 
Ell
template <class Derived> class Base {
typename Derived::DerivedTypedef DoSomething()
}
and a class like this
class Derived : public Base<Derived> {
public:
typedef int DerivedTypedef
}
but it wont compile :o
i get this:
well
 
derived isn't a complete type
put it in a wrapper class
 
Ell
sorry I don't quite understand - why does it need a wrapper class?
and what kind of wrapper class?
 
let me write example
 
Ell
7:09 PM
thank you
ahh I think I have found an example of this in this SO question
9
Q: C++ static polymorphism (CRTP) and using typedefs from derived classes

Sam PowellI read the Wikipedia article about the curiously recurring template pattern in C++ for doing static (read: compile-time) polymorphism. I wanted to generalize it so that I could change the return types of the functions based on the derived type. (This seems like it should be possible since the bas...

 
yeah, that's it
 
Ell
it looks awfully complicated o.O
 
8:00 PM
what's the difference between std::next() and std::advance()?
 
std::advance returns void and mutates one of its argument.
And of course you get to pick the distance to advance.
 
@LucDanton next allows that too.
 
@RMartinhoFernandes A name that defies expectations -- bad design!
 
on the face of it it looks like a hint of a new direction standard C++ is taking: humane interface in favour of a minimal interface.
> Equivalent to std::advance(it, n);
 
It's "Equivalent to std::advance(it, n); return it;".
 
8:05 PM
yeah.
well
makes sense, i suppose.
i think it's to encourage using the "advance()" functionality. one line of code less, because it returns its value.
but then they should deprecate std::advance(). to keep the library small.
 
It also works with rvalues: auto in_the_middle = std::next(container.begin(), 5);
 
or maybe not.
well i'd think rvalue are the whole point here.
they're raison d'etre is to allow return by value
did they also do something to reduce lines of code in reserve()ing? so the reserve() idiom doesn't take an extra line of code?
but, does anything stop you from saying std::next(nullptr, 1) ?
because you can't do that with std::advance()
 
std::nullptr_t doesn't conform to an iterator concept, so I don't think that can work.
 
Xeo
int main(){
	auto x = nullptr;
	x + 5; // error C2389: '+' : illegal operand 'nullptr'
}
 
concepts never got through, so they're the same as in c++03: you may or may not get an error...
 
8:16 PM
You will get an error.
 
Xeo
^this.
 
Whether you get an error or not doesn't change how valid it is or not, which I was referring to.
 
It may not be very readable, but there will be an error.
 
Xeo
std::nullptr_t has no operator+. It may be convertible to any pointer type, but for operator+, which should it convert to?
 
std::next() only uses + for random access.
but yeah.
 
Xeo
8:19 PM
std::nullptr_t also has no operator++. :P
 
The same that was said two seconds before.
 
i wish containers got ctors for reserving only.
 
Yeah, that would be nice.
 
std::vector<int> v(100);  // reserve
but it'd break old code.
 
Xeo
std::vector<int> v(std::reserve_tag, 100); // reserve
would not
 
8:21 PM
well that's ugly :p
 
@Xeo Dammit, stop saying what I'm about to say!
 
maybe std::make_reserved<std::vector<int>>(100)
 
Xeo
I'm the superior bot.
:D
@wilhelmtell that is ugly
 
lol
 
Xeo
Also, how would that work?
 
8:22 PM
the usual way. just wrapped into a function and using move semantics.
 
T t; t.reserve(n); return t;?
 
Xeo
std::vector<int> v(std::make_reserved<std::vector<int>>(100)); // v still not reserved
 
why not?
 
Because it's missing a parenthesis!
 
Xeo
copy-swap for shrinking uses exactly that property
 
8:23 PM
@Xeo But that's a move.
 
Xeo
capacity is not copied
 
but no copy!
 
Xeo
hmm
Okay, with moving it would work
 
also, you can use auto for the first vector<int>.
 
auto v = std::make_reserved<std::vector<int>>(100);
 
Xeo
8:24 PM
still looks hella ugly in comparision to std::vector<int> v(std::reserve, 100);
 
auto v(std::make_reserved<std::vector<int>>(100))
 
I do prefer the taggy version. It kinda looks like a named ctor.
 
Xeo
the taggy version is also what is used by the stdlib for allocator arguments
 
std::vector<int> v(std::with_reserve = 100); !
 
but it feels wrong because, for iterators, they use this trick only behind the scenes. users are not supposed to do that.
so it feels out of place.
 
8:26 PM
@LucDanton std::with_capacity.
 
Xeo
Tags are a good concept, no need to hide them
 
Just because there is something called 'iterator tags' doesn't mean that everything else with 'tag' in the name is the same.
 
Xeo
@RMartinhoFernandes Also, please no assignment. std::with_capacity_of(100)
 
@jalf But it doesn't run on GPU. It's just an utility lib.
 
@RMartinhoFernandes Aha, but reserving is a capacity request. The final capacity may be higher (I think?).
 
Xeo
8:27 PM
@LucDanton Yes
 
I've been using name { value } for my named args.
 
it feels wrong because your code is there for technical reasons, not because it actually expresses something you want to say. it's not part of what's being done, but to help you get there. and that to me feels wrong.
 
@LucDanton with_capacity_for :P it guarantees capacity for n.
 
@Xeo ok that's fine!
 
Xeo
@RMartinhoFernandes That's good for disambiguation of the vexing parse
 
8:29 PM
I wonder if I should name all of my named parameters like so. I already have with_deleter, I could change all the others like raw to with_raw.
 
Xeo
@LucDanton Does the assignment op produce a new object?
 
@LucDanton reserving_for(100) ?
 
with_xxx sounds like noise.
 
@Xeo Yes.
 
It wouldn't make sense everywhere.
 
Xeo
8:30 PM
with_xxx = yyy sounds like Haskell, tbh
 
@CatPlusPlus Trying to find a balance between useful information ("this is a named parameter") and overstating the obvious ("I know").
 
@Xeo That would be withXxx.
And no assignment.
 
@Xeo Not really, no.
 
What if I come back some months later and find foo(with_bar = quux); in my code? What's the assignment doing here?
 
Anyone who knows about named parameters can tell what it is. Anyone who doesn't will wonder anyway, no matter how you name them.
 
8:31 PM
auto v = std::make_vector<int>() << std::reserve(100);
 
Xeo
@wilhelmtell Like, well, no.
 
std::make_vector<int>(capacity = 100)
 
lol
 
@CatPlusPlus Right, but I'm emulating named parameters. By abusing assignment syntax.
 
8:33 PM
@CatPlusPlus s/python/c++/
 
I'm not sure why I picked with_deleter as the parameter name, either.
 
I prefer good ole initialization syntax.
 
I think I read the parameter in make_unique<T>(with_deleter = foo); as "with deleter equals to foo". I guess it reads nicely?
 
how did they manage to fix the templates >> issue? the issue was that operator parsing was greedy by nature...
 
But I guess that doesn't work when I want to use more generic stuff.
 
8:35 PM
They've made the grammar even more convoluted than before.
 
you mean more context dependent?
no but i mean, this issue is as low as tokenizing
 
We need more pairs of balanced characters.
Unicode to the rescue?
 
In this instance (i.e. template parameter list) >> is special-cased to be interpreted as > >. Unless it can't work, then it's >>.
 
@RMartinhoFernandes oh god NO
 
8:37 PM
@LucDanton but it's a tokenizing issue
the tokenzier is (supposedly) a very dumb thing.
i don't think it has a lot of context knowledge.
 
Look, I found the bananas. std::vector⦇std::vector⦇int⦈⦈.
 
@RMartinhoFernandes yeah i can see why @litb left now
 
Xeo
#include <vector>
#include <iostream>

struct with_capacity_for_t{
	struct capacity_holder{
		capacity_holder(unsigned cap)
			: _cap(cap) {}

		template<template<class,class> class X, class T, class A>
		operator X<T,A>() const{
			X<T,A> t;
			t.reserve(_cap);
			return t;
		}

		unsigned _cap;
	};

	capacity_holder operator=(unsigned capacity) const{
		return capacity_holder(capacity);
	}
} with_capacity_for;

int main(){
	std::vector<int> v(with_capacity_for = 100);
	std::cout << v.capacity() << '\n';
:D
 
@wilhelmtell What do you mean "@litb left"?
 
the problem with tags is that they can cause constructor explosion as you add tags. and they're not reusable in the sense that you need to duplicate the functionality across containers, because ctors must be members.
 
8:41 PM
@Xeo Hmm, that's a neat trick to "overload on return value".
 
Xeo
Strangely enough the above code is ambiguous with a variadic template
 
@wilhelmtell Talk to the committee, because that's not my problem: "[...] Similarly, the first non-nested >> is treated as two consecutive but distinct > tokens, the first of which is taken as the end of the template-argument-list and completes the template-id." From n3290, 14.2 Names of template specializations [temp.names], paragraph 3.
 
@RMartinhoFernandes i donno i saw his avatar left two moments after you posted the unicode sample thingy. :p
 
Xeo
lawl
 
8:43 PM
Now I have to write the bananas operators in Haskell.
Let's just hope those things count as punctuation.
 
Xeo
@RMartinhoFernandes The problem with that with_xxx = yyy syntax is that you need to employ such a trick in order to support all kinds of reserve-aware containers. With tags, there is no such problem
 
i remeber there was a programming language based on unicode characters. something in the domain of math.
 
right
 
Not Unicode, but the same kind of crazy.
 
8:44 PM
@Xeo FWIW my named parameters usually delegate to a tagged overload. Where the tagged overload simply uses the types of the parameters names.
 
yeah, before the days of unicode.
 
So make_unique<T>(with_deleter = foo) will call template<typename Deleter> R make_unique(with_deleter_t, Deleter&&);
 
Dammit, Consolas doesn't have bananas. Anyone know of a fixed width font with good Unicode support?
 
A macro (using some Boost.PP magic) can help write the named overload.
 
> a.hs:5:2: lexical error at character '\10631'
 
Xeo
8:48 PM
haha
 
Dammit, not valid punctuation.
 
9:05 PM
I am confused about NFAs, how can there be 2 edges with the same symbol?
 
Xeo
Damn, I can't boot my Debian vbox on my friend's laptop. :(
 
@RMartinhoFernandes No such thing. Only varying degrees of "bad support".
 
@CatPlusPlus Well, I can settle for the less bad one.
Do you have names?
 
Is there a font with the POO, PILE OF character?
 
Symbola.
Not usable for programming though.
That is, unless you're one of those wackos that use proportional fonts.
 
9:16 PM
It would be cool to have a font that has both a banana and a pile of crap.
Because then we could write "this shit is bananas".
 
This 💩 is 🍌s.
 
Xeo
struct foo{
  unsigned shit;
  void bar(unsigned bananas){
    this->shit = bananas;
  }
};
 
@Xeo I... hate you. That's horrible and hillarious at the same time.
 
Xeo
?
 
Markdown wins again.
 
9:20 PM
FUCK IT
 
Xeo
4 char indent, aka "fixed font"
 
Yeah, I'm still a noob in markdown
 
Xeo
multiline markdown 14 : 0 users who can't read / remember the newbie hints
 
STILL
if(this.Shit is Bananas)
 
I think there might be something philosophically wrong with exception handling for destructors in C++. I feel like there should be a mechanism for handling errors thrown in destructors, but the only thing I can think of is extra code to manually "destruct" the object before the destructor is actually called. Like ostream.close. But that doesn't really feel like RAII anymore.
 
Xeo
9:22 PM
We need a proper exception stack
 
throw_with_nested.
 
Also fails for containers
@Xeo proper exception stack? You mean nested exceptions?
 
If an exception is thrown when destroying stuff while unwinding stack to throw some exception, it gets throw_with_nesteded instead of std::terminateing the whole thing. I think that could be made to work.
 
@RMartinhoFernandes you need a container to keep exceptions thrown during unwinding
 
std::exception_ptr is that container.
 
9:24 PM
@Abyx Why not use the exception itself as the container?
 
@RMartinhoFernandes you can already do that with C++, I'm talking about what if std::unique_ptr's destructor throws an exception, and fails to release the memory? That's a memory leak that C++ is completely incapable of handling
 
@MooingDuck That's hopeless isn't it?
 
@MooingDuck Why would it throw?
 
I mean that during unwinding you can get thousands of throws
 
@EtiennedeMartel heck if I know for unique_ptr. The point is RAII destructors can throw, which is a resource leak.
 
9:26 PM
std::unique_ptr::~unique_ptr doesn't throw.
 
@MooingDuck No they can't.
 
The language allows destructors to throw, but they can't.
 
@RMartinhoFernandes what do you mean they can't?
 
Actually, "dispose" operations (closing a file, releasing memory, etc.) are not supposed to fail.
 
Xeo
They can't if you don't want your app to die.
 
9:27 PM
not "can't" but "shouldn't"
 
@MooingDuck If you throw from a destructor while the stack is being unwound because some exception was thrown, the process is std::terminated.
 
@EtiennedeMartel they're not supposed to, because C++ cannot handle that situation.
 
Xeo
std::terminator'd
 
@MooingDuck Who can handle that situation?
If the cleanup code fail, it's hopeless.
 
there are some use cases when it's useful to have throwing destructor
 
9:28 PM
@RMartinhoFernandes what if it's not being unwound because of some exception, but simply went out of scope.
 
The only things you can if cleanup fails are: bring the whole thing down, or go on with the leak.
 
@RMartinhoFernandes again, I know that. I think there is a non-C++ model that could theoretically handle it though.
 
Xeo
@MooingDuck Then everything is "fine"
 
hi
 
Xeo
You just can't throw while an exception is active
Unless you want to burn your app
 
9:29 PM
which room is good room to ask mysql questions in?
 
@Xeo That allows resource leaks. Sometimes lots of them
 
@MooingDuck I don't think there is. I'm not talking about C++ specifically.
 
@Droopov any other
 
Xeo
@MooingDuck Huh?
 
@MooingDuck If the code that can fix the leak fails, you don't have a choice.
 
9:30 PM
chill much, Abyx
 
-2
Q: Time to cast: which is the fastest?

Phoenica MaciaDoes anyone know which following casts: reinterpret_cast static_cast dynamic_cast const_cast Implicit Type Conversions C-Style Casts operates the fastest?

Damn.
 
wow, that one went down fast...
 
what?
 
Yep.
Hyperfast termination!
 
9:31 PM
@Xeo if you have a vector of 1000 smart pointers (to data on a networked machine), which goes out of scope, and the network is disconnected, so the first pointer's destructor throws an exception, C++ offers absolutely no way to wait for reconnect/try again/send failure notification/log what leaked/anything at all. All those resources are leaked permanently. The most C++ can do is say that something leaked.
 
OP lost all his/her rep
 
@MooingDuck Why would the pointer throw?
 
Xeo
@MooingDuck nested try-catch in a while loop? xD
 
dynamic_cast should be slowest, intuitively...
 
Xeo
I know the fastest.
 
9:32 PM
RTFM
 
But then, if you're having fun with data over a network, I don't think that standard issue RAII is going to help you.
 
@EtiennedeMartel if it's a smart/network pointer.
 
Xeo
template<class T>
T&& nop_cast(T&& t){
  return std::forward<T>(t);
}
 
It's pointer-shaped pain.
 
Make the pointer smarter.
3
 
9:33 PM
@EtiennedeMartel yeah, C++'s implimentation of RAII won't work there
 
went down faster than spam usually does - and it arguably isn't spam, lol
 
@RMartinhoFernandes that's a possibility.
 
Put your "last hope" code in the destructor.
Because the destructor is the last hope.
If it fails, you should be screwed.
 
@MooingDuck .NET's Dispose pattern won't work either.
 
@RMartinhoFernandes another option I just thought of is to move those about-to-be-leaked resources to the exception to be handled.
 
9:34 PM
@MooingDuck By whom?
 
@EtiennedeMartel I know of no current implimentation that does work
 
The most qualified person to handle those just failed to do so.
 
@RMartinhoFernandes it becomes the equivalent of a bad_alloc, someone has the option to catch it and say "try again" or "log this". At least you can log a resource identifier of some sort.
 
But that won't fix the leak.
Unless you put (abstraction) leaks all over your abstraction.
 
@RMartinhoFernandes if the exception has a "try again" that's an option. Or even the ability to log the resource ID would be good.
 
Xeo
9:36 PM
~someclass(){
  bool done = false;
  while(!done){
    try{
      // ...
    }catch(...){
      continue;
    }
    done = true;
  }
}
 
I'm liking the idea of a smarter RAII exception.
 
@MooingDuck But now your exception needs to carry around a copy of the object that was destroyed.
 
@RMartinhoFernandes yeah, I don't see a problem with that.
 
Xeo
@MooingDuck What if the copy construction throws?
 
@MooingDuck The problem is that the object was not really destroyed.
 
9:38 PM
@RMartinhoFernandes that's why there needs to be a copy somewhere
@Xeo there's standard C++ ways to handle that.
 
If you want control, put mechanisms for it, like close() functions.
The destructor is the last hope.
2
 
Xeo
@MooingDuck Eh? If the copy to the exception throws, you just threw another exception during an exception -> bye bye app
 
@RMartinhoFernandes that is a C++ option, but feels like a workaround of the RAII concept.
 
@Xeo We're assuming a world where that doesn't happen.
@MooingDuck But a workaround of RAII sounds exactly like what you want!
 
Xeo
@RMartinhoFernandes Copy can reasonably fail though. bad_alloc would be the easiest
 
9:39 PM
@Xeo Worst case you can built an exception stack in C++.
 
@Xeo No, I mean, we're assuming exceptions when throwing exceptions do not std::terminate (otherwise there's no point in discussing exceptions leaving dtors).
 
@RMartinhoFernandes no, I'm saying, standard C++ has workarounds and failures for the RAII concept. I'm trying to think of how to fulfill the RAII concept.
 
Xeo
@RMartinhoFernandes Ah
moving the half-dead object into an exception would might work though
 
I misread.
 
@Xeo Yeah, that's what I was thinking origionally, sorry if I said something else.
@RMartinhoFernandes at the point where the exception was thrown, the destructor hasn't completed yet.
@Xeo I'm sorely tempted to try to write this all in C++ now. A RAII-destructor-exception. Maybe an exception stack as well while I'm at it. Too bad I'm at work :(
 
Xeo
9:44 PM
I'm at it already :)
 
The aggregate exception is not the hard part. The hard part is fighting language semantics.
 
@Xeo I like this. exceptions stay in memory until they're "handled" anyway, so this forces memory to be released, even in failure conditions.
 
Throwing something from a destructor is going to end badly.
 
@RMartinhoFernandes which parts do you think will get in the way? I think an RAII-destruction-exception should handle everything nicely.
 
@MooingDuck Which part? std::terminate.
You can't safely throw from destructors.
 
9:46 PM
it depends on usage of object
 
@RMartinhoFernandes it's possible to check if an exception is already being thrown, in which case you use an exception stack. Or nest. Whichever.
 
temporary object can safely throw from destructor, if nothing will throw while it's alive
 
@MooingDuck You can check if an exception is being handled.
 
@Abyx origional context was a smart pointer that might throw an exception from it's destructor
 
I don't know what that means exactly.
Oh wait, there's uncaught_exception.
 
Xeo
9:49 PM
yep
 
@RMartinhoFernandes if (std::uncaught_exception()) exceptionstack.push(std::RAII_error(ptr_); else throw std::RAII_error(ptr_);
 
But you can't get at the current exception.
How do you plan to modify it?
 
@RMartinhoFernandes exception stack as a workaround since you can't
 
@MooingDuck A global?
 
Xeo
std::current_exception
 
9:51 PM
@Xeo I learn something new every day
 
@Xeo Returns null unless a handler is running.
 
Xeo
ah, damn
 
@RMartinhoFernandes not if it's a queue
 
Now that sounds like errno, GetLastError, and friends.
 
Xeo
xD
 
9:53 PM
@RMartinhoFernandes whatever it takes to fullfill the RAII concept and not slow my code much. Plus a global exceptionstack class can be a stack/queue.
 
@MooingDuck What difference does it make being a queue? It still needs me manually checking it.
 
@RMartinhoFernandes it only needs checking in the handler though, since if the queue is in use, an exception is already being thrown
Though I'm unsure how one would handle the errors after the first.
 
That's just more boilerplate. I don't think it's a big improvement over a function that does a controlled release.
 
Xeo
huh....
why does an exception thrown from main not let me break inside a destructor? oO
 
Optimization?
 
9:57 PM
@RMartinhoFernandes you would rather have a while(resource) { try {resource.release(); } catch(...) {} } for every resource that you want to release?
 
Xeo
debug mode
 
@Xeo What happened? It terminated?
 
@MooingDuck That pattern can be captured into a RAII class.
Pulling from a queue on every catch can't.
 
@RMartinhoFernandes oh, gotcha. I suppose that's an option too.
 
Xeo
"first chance exception at...."
 
9:59 PM
@Xeo doesn't MSVC do that when the exception is thrown? If so, no destructors have run yet
 
Xeo
What the...
even with a try-catch block
 

« first day (439 days earlier)      last day (4525 days later) »