Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411671 Posts in 69397 Topics- by 58452 Members - Latest Member: homina

May 16, 2024, 04:36:19 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)The happy programmer room
Pages: 1 ... 255 256 [257] 258 259 ... 279
Print
Author Topic: The happy programmer room  (Read 680074 times)
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #5120 on: November 17, 2017, 10:26:09 AM »

It's just a container for a value of any type. As in, you can declare a variable of type std::any, initialize it with an int and then later assign it a string with no problems.
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #5121 on: November 17, 2017, 11:55:03 AM »

so it's a variant?

I hate how C++ redefines words that are consistent in almost every other language Sad
Logged

oahda
Level 10
*****



View Profile
« Reply #5122 on: November 17, 2017, 12:01:36 PM »

No, that's std::variant. c;

I have no idea about conventional terminology, but std::variant is basically a "typesafe union" while std::any is basically a "typesafe void *".
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #5123 on: November 17, 2017, 12:13:53 PM »

Quote
The class any describes a type-safe container for single values of any type.

So, variants hold actual objects, and anies (my best pluralisation of any) only hold a value, correct?
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #5124 on: November 17, 2017, 12:46:44 PM »

No, that's std::variant. c;

I have no idea about conventional terminology, but std::variant is basically a "typesafe union" while std::any is basically a "typesafe void *".

Any generally means a function that if given a predicate returns true if any item in a target collection satisfies the predicate. If it is parameterless then it tells you whether or not the collection is empty. Off the top of my head Haskell, C# and ruby use that definition. I think f# does too.

I'm not sure I see the practical difference between variant and any. I will have to think on that for a bit.

EDIT : Ok I read the variant spec. I know this is nitpicking but the description makes me feel like std::variant should be std::discriminated_union and std::any should be std::variant.

« Last Edit: November 17, 2017, 12:57:08 PM by InfiniteStateMachine » Logged

Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #5125 on: November 17, 2017, 03:16:57 PM »


std::any is in C++17? About time it made the standard library. Wink

I've been using boost::any for years now. It's a very clever hack and it blew my mind when I first encountered it. Very nice when you want to pass around or hold a type-safe opaque reference to a resource without imposing any restrictions whatsoever on what the resource can be.


I just looked up the definition for std:any and I'm a little confused.


I think of it as a typesafe and type-aware mish-mash of a void pointer that is aware of destructors yet still accepts scalars. Or as a magic box that you can put anything in that you can pass through a framework that doesn't need to understand it that you can unpack at the other end. It's an opaque container that can be passed through code that doesn't understand it that can be reopened later by code that does.

It is an excellent upgrade from the generic void pointer that some libraries hold to provide context when they make callbacks into the code that called then. It works well both as a context argument for such calls and something that you set up during initialisation.

I was a little surprised when it didn't make it in C++11, and completely stunned when it didn't make C++14. It's small, simple, elegant, and amazingly useful. It's also something that would benefit from standardisation to simplify how it determines type equivalence.

Is this another case where they took a well known programming term and changed its meaning?

I don't mind the name myself, but I can imagine it would be pretty jarring if you've normally been using the term in another context.

Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #5126 on: November 17, 2017, 04:08:20 PM »


I don't mind the name myself, but I can imagine it would be pretty jarring if you've normally been using the term in another context.



Yeah ultimately I don't REALLY mind but I do find it a little annoying that they seem to often just ignore the rest of the programming world which has to some degree standardized the naming for the features they are pulling into STL.

Also the fact that any sounds like variant and variant sounds like a discriminated union is just weird to me. I'm probably missing something...
Logged

Crimsontide
Level 5
*****


View Profile
« Reply #5127 on: November 17, 2017, 04:57:19 PM »

EDIT : Ok I read the variant spec. I know this is nitpicking but the description makes me feel like std::variant should be std::discriminated_union and std::any should be std::variant.

Like std::vector should be called array Smiley
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #5128 on: November 17, 2017, 05:03:46 PM »

that too!

Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #5129 on: November 17, 2017, 05:30:12 PM »

but std::array is a thing already, it's a static list of stuff.
Logged

Crimsontide
Level 5
*****


View Profile
« Reply #5130 on: November 17, 2017, 05:55:30 PM »

but std::array is a thing already, it's a static list of stuff.

Well, std::vector is more like an array, and std::array is more like a vector.  Or perhaps fixed_array, static_array?  Generally fixed sized homogeneous lists are called vectors (at least in math, if they are small-ish).  Variable sized larger homogeneous lists are called, well lists, but occasionally arrays.

Bottom line is, naming in the std seems to be umm... not good?
Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #5131 on: November 17, 2017, 11:24:31 PM »


Yeah ultimately I don't REALLY mind but I do find it a little annoying that they seem to often just ignore the rest of the programming world which has to some degree standardized the naming for the features they are pulling into STL.

C++ is an old language designed for compatibility with an older language (C). I'd bet many things would have ended up very differently (especially the naming) if it was designed from scratch nowadays.

Also the fact that any sounds like variant and variant sounds like a discriminated union is just weird to me. I'm probably missing something...

I'm not sure you're missing something as such. Thinking about it, there are more than a few things that are named in unusual ways. You've picked up on it faster than I did.

Like std::vector should be called array

Sign me up, I'm in. :D

Did std::vector predate std::array, or at least appear at the same time? I can't remember. I wonder if there was the opportunity to give them this name. I suspect it was never going to be called array due to the C heritage though. Update: I think std::array was C++11, which would mean std::vector did predate it. Does anyone know for sure?

but std::array is a thing already, it's a static list of stuff.

It's the closest to a C array, and probably got the name for that reason.

Generally fixed sized homogeneous lists are called vectors (at least in math

I think that's (the basis of) a good argument to call a fixed-size array a vector. Mathematics should be pretty high up the list when considering naming for programming languages. A math vector is generally a fixed size. A variable-sized vector (something that you'd add or remove elements from) would be a set rather than a vector. I'm used to "array" meaning an array of data of fixed size, but I suspect I think this only because of the use of the term in a C context. Interesting. Smiley

Or perhaps fixed_array

I like fixed_array as well. It's really a special case of a variable-sized array with optimisation possibilities.

Logged
JWki
Level 4
****


View Profile
« Reply #5132 on: November 18, 2017, 01:18:40 AM »

std::vector has been around for ages, std::array is prettyyyy recent. And yeah the naming is pretty shit. I also disagree that mathematics should be the first thing to look at when naming things - have you read code written my mathematicans? It's terrifying. And even looking at maths, std::vector has nothing to do with a mathematical vector - to make something a vector, it has to satisfy all the semantics of a vector and that's not the case for std::vector at all.
Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #5133 on: November 18, 2017, 04:17:07 PM »


std::vector has been around for ages, std::array is prettyyyy recent. And yeah the naming is pretty shit. I also disagree that mathematics should be the first thing to look at when naming things - have you read code written my mathematicans? It's terrifying. And even looking at maths, std::vector has nothing to do with a mathematical vector - to make something a vector, it has to satisfy all the semantics of a vector and that's not the case for std::vector at all.

https://xkcd.com/435/
Logged
powly
Level 4
****



View Profile WWW
« Reply #5134 on: November 19, 2017, 08:11:14 AM »

Generally fixed sized homogeneous lists are called vectors (at least in math

I think that's (the basis of) a good argument to call a fixed-size array a vector. Mathematics should be pretty high up the list when considering naming for programming languages. A math vector is generally a fixed size. A variable-sized vector (something that you'd add or remove elements from) would be a set rather than a vector. I'm used to "array" meaning an array of data of fixed size, but I suspect I think this only because of the use of the term in a C context. Interesting. Smiley
A “vector” in math is a very abstract concept and usually viewed as a single instance or element in itself. It might happen to have a nice basis representation (a list of numbers corresponding to weights of basis vectors) or it might not.

Lists and sets in mathematics are generally immutable, if we want to add or remove things we define a new list or set with a different name.

I’d go for the other route and call vector a dynamic_array or similar but it might be just being so used to arrays meaning statically sized ones.
Logged
Ordnas
Level 10
*****



View Profile WWW
« Reply #5135 on: November 20, 2017, 12:43:56 AM »

Generally fixed sized homogeneous lists are called vectors (at least in math

I think that's (the basis of) a good argument to call a fixed-size array a vector. Mathematics should be pretty high up the list when considering naming for programming languages. A math vector is generally a fixed size. A variable-sized vector (something that you'd add or remove elements from) would be a set rather than a vector. I'm used to "array" meaning an array of data of fixed size, but I suspect I think this only because of the use of the term in a C context. Interesting. Smiley
A “vector” in math is a very abstract concept and usually viewed as a single instance or element in itself. It might happen to have a nice basis representation (a list of numbers corresponding to weights of basis vectors) or it might not.

Lists and sets in mathematics are generally immutable, if we want to add or remove things we define a new list or set with a different name.

I’d go for the other route and call vector a dynamic_array or similar but it might be just being so used to arrays meaning statically sized ones.

I found that Alex Stepanov, designer of the STL, admits that he made a mistake naming it std:vector, he was looking for a name to distinguish it from built-in arrays:
https://stackoverflow.com/questions/581426/why-is-a-c-vector-called-a-vector
Logged

Games:

Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #5136 on: November 20, 2017, 03:14:16 PM »

but it might be just being so used to arrays meaning statically sized ones.

One thing I found interesting on self-reflection is that when I'm in a C/C++ mindset and think arrays, I tend to consider the obvious thing to be fixed-size arrays; but when I'm in a Ruby mindset, I consider the obvious thing to be variable-length arrays. Both can't be true. My perception of what is obvious is coloured by what is expected of the language I am thinking about. Taking a step back, and forcing myself to choose one of the options, I find myself leaning toward an array being of variable size.


I found that Alex Stepanov, designer of the STL, admits that he made a mistake naming it std:vector, he was looking for a name to distinguish it from built-in arrays:
https://stackoverflow.com/questions/581426/why-is-a-c-vector-called-a-vector

Nice find. I wasn't aware that even the person who named them regrets the name.
Logged
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #5137 on: November 21, 2017, 07:43:16 AM »

Working on a renderer. Hierarchical bone animation seems to be in good shape:



Next up is model loading so I don't have to type in all those vertices, joints, weights, normals, etc. by hand...
Logged

oahda
Level 10
*****



View Profile
« Reply #5138 on: November 21, 2017, 07:50:28 AM »

Welcome to the club!
Logged

popawheelie
Level 0
***


View Profile
« Reply #5139 on: November 21, 2017, 09:38:04 AM »

Hi, just discovered this thread and read back a few pages.

Jumping in to the middle of the conversation, Ill say that I'm a fan of stl, but hate the syntax. To get around this, I created a wrapper class that accesses the stl functions. The initial motivation behind this was so I could easily adapt to anyone's memory system. All I need to do is modify the wrapper to adapt to the new system. In use, I always access my wrapper class and not stl directly.

I've been working on a destruction engine which I'd like to adapt to other systems so the approach has worked well.



Cheers,
H
 Beer!
Logged

Pages: 1 ... 255 256 [257] 258 259 ... 279
Print
Jump to:  

Theme orange-lt created by panic