last day (1092 days later) » 

7:36 PM
:O
 
whoo
 
IT LIVES
 
What does he mean by emplace support?
This code works fine
#include <gears/any.hpp>
#include <vector>
#include <iostream>

using gears::Any;

int main() {
    std::vector<Any> v;
    v.emplace_back(40);
}
 
That makes the first any and integer, right?
 
Yes
int main() {
    std::vector<Any> v;
    v.emplace_back(40);
    std::cout << v[0].as<int>();
} // prints 40
So I'm confused!
 
7:39 PM
#include <gears/any.hpp>
#include <vector>
#include <iostream>

using gears::Any;

struct BreakAny {
     int x;

     BreakAny( int val ) : x (val) {

     }
};

int main() {
    std::vector<Any> v;
    v.emplace_back( 40 ); // But I wanted to `emplace` a BreakAny :[
}
If I tried to .as() that as a BreakAny, any would break.
 
#include <gears/any.hpp>
#include <vector>
#include <iostream>

using gears::Any;

struct BreakAny {
     int x;

     BreakAny( int val ) : x (val) {

     }
};

int main() {
    std::vector<Any> v;
    v.emplace_back(BreakAny(40)); // But I wanted to `emplace` a BreakAny :[
} // compiles
 
Ah, but it gets stickier.
 
:(
 
Imagine this:
 
how so? How does your code do it then?
 
7:40 PM
#include <gears/any.hpp>
#include <vector>
#include <iostream>

using gears::Any;

struct BreakAny {
     int x;

     BreakAny( int val ) : x (val) {

     }

     BreakAny ( const BreakAny& ) = delete;
     BreakAny ( BreakAny&& ) = delete;
};

int main() {
    std::vector<Any> v;
    v.emplace_back(BreakAny(40)); // But I wanted to `emplace` a BreakAny :[
} // compiles... ?
 
Not without BreakAny(BreakAny&&)
It has to be movable.
 
No, no it doesn't.
 
No, I mean it legitimately has to be
The underlying type is an std::unique_ptr
 
Data inside a std::unique_ptr can be non-moveable, I think.
 
If you take off the BreakAny(const BreakAny&) = delete it'll work fine
but since you deleted the move, it won't do it
error: use of deleted function 'BreakAny::BreakAny(BreakAny&&)'
         Derived(U&& v): value(std::forward<U>(v)) {}
 
7:45 PM
Hm.
I wonder if my any can handle it.
 
try it I guess
 
^ Can your any handle that by itself?
 
Yes, though mine isn't that bad-looking.
 
Show me. :D
 
I can't do it if the functions are deleted (like I said earlier)
but
#include <gears/any.hpp>
#include <iostream>

using namespace gears;
struct BreakAny {
     int x;

     BreakAny( int val ) : x (val) {}
};

int main() {
    Any k;
    k = BreakAny(42);
    std::cout << any_cast<BreakAny>(k).x << '\n';

    k = 1.1;
    std::cout << k.as<double>() << '\n';
    k = 1.5;
    std::cout << k.as<double>() << '\n';
    try {
        std::cout << k.as<float>() << '\n';
    }
    catch(...) {
        std::cout << "Exception caught\n";
    }
}
Hmm.. I could probably fix that construction thing if I tried. The errors aren't too bad
 
7:56 PM
Good luck. :D
 
Oh, yeah it isn't a big deal.
Just like one line of code
BTW this is the underlying type
    template<typename T>
    struct Derived : Base {
        template<typename U>
        Derived(U&& v): value(std::forward<U>(v)) {}
        T value;

        std::unique_ptr<Base> clone() const {
            return std::unique_ptr<Base>(new Derived<T>(value));
        }
    };
 
That's only forwarding a single type, though
E.g., try something like...
struct BreakAny {
     int x;
     float y;

     BreakAny( int val, float fval ) : x (val), y(fval) {}

     BreakAny( const BreakAny& ) = delete;
     BreakAny( BreakAny&& ) = delete;
};
^ Try to build that with your current Any.
 
If I take off the deleted functions it'll work
O_o
That isn't even my point of interest, it's getting the deleted functions to work
(If it became a problem making it variadic might solve the issue, but as it stands now it isn't :|)
 
(Making it variadic solves the two-parameter constructor issue. The deleted function issue is related to variadic forwarding: e.g., your any seems to be assuming it's copy or move constructible, when it's neither)
 
Hmmm
@ThePhD k = BreakAny(42,3.2f); <-- works fine but it has to be movable/copyable
and doing any_cast<BreakAny>(k).y would print 3.2 as expected
 
8:07 PM
Yeah, that's what I'm getting at.
If it's not copyable or moveable, how do you get it in any?
That's the challenge. :D
 
Hm, with the current interface I'm at it probably isn't very possible (nor do I actually care that much about emplacing)
the emplace construction is basically <typename... Args> void emplace(Args&&... args) with them being std::forwarded
 
Mmhmm.
That's also how you dodge the noncopyable nonmoveable bullet as well.
 
but even if it doesn't emplace properly I still like it better ~
 
Yeah, it is nice.
 
The interface isn't redundant and you don't have to specify the type
 
8:13 PM
I'm going to clean my interface up some more
 
Defeats the purpose of type erasure for me
Why use an Any if I'm already specifying the type at construction?
BTW try making a variant
Any is barely 80 LOC
but the variant class I made is ~500
 
I think I can do variant easily.
 
I haven't added it to my gears repo because it's too ugly
template<typename... Args>
    struct do_visit {
        template<typename Internal, typename CVType, typename Visitor, typename... U>
        resultant<Visitor> operator()(Internal&& inte, size_t index, CVType&& cv, Visitor& visitor, U&&... args) {
            using caller = resultant<Visitor> (*)(Internal&&,CVType&&,Visitor&&,U&&...);
            static caller callers[sizeof...(Args)] = { &visitor_caller<Internal&&,Args,CVType&&,Visitor,U&&...>...};
            if(!(index >= 0 && index < sizeof...(Args)))
;-;
 
... Wat.
 
ya.
It's messy.
It's a lot harder than Any
#include "variant.hpp"
#include <iostream>

int main() {
    variant<int,std::string> v("Hello There");
    std::cout << v;
}
 
8:36 PM
to be fair I could clean it up
 
Maybe
I don't think I wanna do variant. D:
 
#include "variant.hpp"
#include <iostream>

class a_visitor {
public:
    using result_type = int;
    result_type operator()(int i) const {
        return i;
    }
    result_type operator()(const std::string& str) const {
        return str.length();
    }
};


int main() {
    variant<int,std::string> v("Hello There");
    std::cout << v << '\n';
    auto result = apply_visitor(a_visitor(),v);
    std::cout << result;
}
(based off the boost example)
It's cool to write.
I hope it gets to the standard one day
Mine's pretty bad.
It's just a shortened C++11 version of boost's
with a few design changes here and there
 
So you'd apply the visitor for the type you wanted?
 
Yes.
If v was an int, it'd return the int associated.
So
int main() {
    variant<int,std::string> v("Hello There");
    std::cout << v << '\n';
    auto result = apply_visitor(a_visitor(),v);
    auto& str = get<std::string>(v);
    str.push_back('!');
    std::cout << v << '\n';
    std::cout << result;
    v = 101;
    result = apply_visitor(a_visitor(),v);
    std::cout << '\n' << result;
}
would print
Hello There
Hello There!
11
101
 
Ooh.
... Interesting.
 
8:50 PM
(I had a static_visitor<T> like boost too but for some reason it isn't working properly.. lol)
 
I like apply_visitor better anyhow.
 
static_visitor<T> is just so you can inherit it and then you can omit using result_type = int.
You'd just do class a_visitor : public static_visitor<int> {
I thought a simple typedef/using would do but I get maximum recursion template depth errors so something obviously fucked up hardcore there.
 
9:25 PM
Meow?
 
Sup?
 
You removed a message.
 
yeah it was a useless one
 
10:02 PM
!! hasn't been active since 2011.
still gets rep.
 
Hahaha
Well, jquery is his gold tag man
It's all about the jquery
 
He's been afk farming rep and got 101k.
That's more rep than Mysticial
 
Dude
Javascript and Jquery are OP.
Also, maybe you should make a query about how much rep has been earned while inactive. :D
 
I'm trying to do some javascript atm actually
without jquery :(
how2blockimagesonclick
 
Ask a question about it.
Get upvotes and rep. :D
 
10:08 PM
ew, asking so questions
 
Are you like the Cat?
Answers only?
 
Yep.
 
10:25 PM
=[
Ask some questions. D:
 
That's for noobs.
TIL about document.images
 
Document.Images?
C# ?
 
JavaScript
I settled for this
javascript:function g(){var j=document.images.length;for(var i=0;i<j;i++){document.images[i].src='http://i.imgur.com/yyttNe4.gif'}}g();;
 
10:53 PM
Oh
So you can loop through all the document's images
 
ya
 
Setting them to a blank thing?
 
that gif is a red x
 
Ooh.
Lulz.
Get BLOCKED, sons.
In either case,
any works just fine in MSVC.
Now I need to do variant, I guess.
and I've already done optional, so.
 
I don't know how to do optional.
and I probably won't do it
It's getting added in C++14
 
10:55 PM
Mmm.
Well then, that works out.
Variant is my next stop then.
 
gl
 
... Blleeeehhhh variant sounds too painful.
I'll just do union. :D
 
#include "variant.hpp"
#include <vector>
#include <iostream>

struct lol {
    using result_type = void;
    template<typename T>
    void operator()(T& op) const {
        op += 62;
    }
};

int main() {
    std::vector<variant<int,std::string>> v;
    v.push_back(100);
    v.push_back("hello");
    for(auto&& var : v)
        apply_visitor(lol(),var);
    std::cout << v[0] << ' ' << v[1];

}
:P
can your unions do this?!
and before you say anything, yes it works with emplace_back
>:|
 
rub it in why don't you ;~;
Also, MAYBE
MAYBE THEY CAN
 
I feel like doing optional<T>
but I need to learn moar haskell.
 
11:01 PM
Wanna see my optional<T> ? :D
 
shit's fun.
if it's anything like your Any, then no.
 
=[
My any is beautiful just the way it is. =[
struct any {
	private:
		struct any_storage {

			virtual void* data () {
				return nullptr;
			}

			virtual std::unique_ptr<any_storage> copy ( ) {
				return std::unique_ptr<any_storage>( nullptr );
			}

			virtual ~any_storage () {

			}
		};

		template <typename T>
		struct typed_storage : public any_storage {
			T item;

			template <typename ...Tn>
			typed_storage ( Tn&&... argn ) : item(std::forward<Tn>( argn )...) {

			}

			virtual std::unique_ptr<any_storage> copy ( ) {
				return std::unique_ptr<any_storage>( new typed_storage( item ) );
BEAUTIFUL.
 
Nah.
Have you seen mine?
It's in RapphD folder
:)
 
I have.
 
under gears
 
11:03 PM
Also, mine works just as good as yours. :c
 
Can yours do Any k = 100.0f
 
Yes!
I fixed it up. :D
 
Shit man, yours is ~3x bigger than mine
and the only added functionality is emplacing
 
And the ability to work with noncopyable and nonmoveable types! ;~;
 
Optional<T> is basically.. a special pointer?
I admit I haven't used it before or had reason to.
 
11:13 PM
Me neither.
But yeah, it's basically a stack-allocated variable.
With a boolean saying whether it exists or not.
TBH I'd rather use a pointer.
 
Seems to be the Haskell Maybe monad.
So hold on
 
Agh
Darn it
My any broke on the noncopyable nonmoveable type. D:
 
#include <utility>

template<typename T>
struct Maybe {
    bool valid;
    T val;
    Maybe(): valid(false) {}
    Maybe(T&& t): valid(true), val(std::move(t)) {}
};
??
 
Uh
Yeah that's one way to do it... ?
Except, val is always default constructed
 
You mean when I'm moving it?
 
11:25 PM
Maybe<NoDefaultConstruct_T>(); // Error!
 
Ah yeah I know what you mean now
Haskell's kinda fun.
 
It is.
Also, ;~;
 
?
 
I can't keep copy on my any
Because it doesn't work with non-copyable types
So no copying any's for me. ;~;
 
gj
 
11:41 PM
Hey, it was necessary. :c
any itself is move-only now but works with all types.
 
Basically useless imo
Looks like you half-invented std::unique_ptr
without using pointers I have no idea how to do optional<T>
:(
 

  last day (1092 days later) »