P z;
X x;
x.p = z;
P z;
X x;
z = x.p;
P z1, z2;
X x;
Q q;
...
z1 = x.p[q];
x.p[q] = z2;
P z;
X x;
Q q;
...
x.p = z; // is the same as
x = z; // because p is a default property
If you want to do that, write a proposal that provides the syntax and
mechanics of how properties would work.
class TimePeriod { private double seconds; public double Hours { get { return seconds / 3600; } set { seconds = value * 3600; } } }
I know this has been discussed many times before with blocked results; but I truly feel if C++ is going to continue outstanding support and popularity into the future it needs to offer the basic idea of a "property". There are many benefits to properties and the only arguments against them are ideological from a don't want to change point of view.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
In C#, the core language feature called Properties works as follows:class TimePeriod { private double seconds; public double Hours { get { return seconds / 3600; } set { seconds = value * 3600; } } }We already have this in C++:class TimePeriod{double seconds;public:struct {operator double() { return seconds / 3600; }void operator=(double value) { seconds = value * 3600; }} Hours;};
Lets just lay it out simple. Almost every programming language under the sun short of C and C++ is supporting the idea of "properties".
If it's such a bad thing why is it so openly supported by most all other competing languages? One just needs to google "How to make C# like properties in C++". People are trying wacky ways to get this support by overloading the '=' operator and other listed here.
If the C++ ISO committee blocks this yet again; it's not a hit to anything but C++. People have requested it; many want it. It does not change any of the previous support/power of C++ so really not having original support is just telling the community who wants them that "we" have another reason to stop you from wanting to using C++.
Apparently many enough don't, since it has been rejected.
How about doing the change in the other end:
Don't change anything in the class head, but allow an implicit transformation:
object.property = value;
to
object.property(value);
IFF property is a function which has an overload that can be called with a single parameter of value's type.
As function pointers and functions are different I don't see that this can interfer with an assignment that is allowed today. Also this is consistent with what is already allowed at construction time!
The getter case is a little harder to accept for me, but I think it would be possible to allow:
int value = object.property;
IFF property is a method which has a 0-ary overload.
I am not positive but at least I think that using the address of a method without a leading & is not allowed when you really want to get at the method pointer, so this should not be ambiguous. In contrast, it would not be possible to omit the trailing () for a global function as (due to feature inheritance from C) this means the address of the function (correct me if I'm wrong on this).
Just wanted to add that MSVC has addressed these issues somehow with their compiler. I'm not sure how they handle it since I'm actually rather a newbie to C++.
After reading N1384 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1384.pdf it appears this could be a user implemented design; but I feel most are going to want some standard langauge / library to make use of it.
__declspec( property( get=get_func_name ) ) declarator __declspec( property( put=put_func_name ) ) declarator __declspec( property( get=get_func_name, put=put_func_name ) ) declarator
--
---
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/n0QcD_K5dBY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
struct S {
int foo() const property;
void foo(int i) property;
};
S s;
s.foo = 42; // rewritten to s.foo(42);
std::cout << s.foo << '\n'; // rewritten to s.foo()
--
Maybe it'd be simpeler to not rewrite 's.foo = 42;' to 's.foo(42);',
but just to 's.foo() = 42;'. That way, there is nothing special about
the assignment operator, just that .foo is implicitly called. That
way, we can support-read only properties by just returning by value or
reference-to-const, read/write by returning a reference-to-non-const,
and support more advanced stuff (with value checking, etc.) by
returning an object of a type with (compound) assignment operator(s)
overloaded.
struct S {
inline int foo() const { return ... }
inline rw_property<int> foo() {
return {
[this]() { return ...; }, // getter
[this](int i) { ... } // setter
};
}
};
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-pr...@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
Gutson’s system adds no state, so copyability isn’t harmed. Unions are copyable as long as all the members are trivially copyable, IIRC.However, I think it’s a non-starter because it only works as long as this is equal to the address of the first member, which is only guaranteed for standard layout types. Adding a non-empty base or a virtual function kills it in practice.
struct property_tag {};
...
union {
property_tag properties;
...
T& self() { return *(T*)((char*)(this) - ((char*)&(((T*)this)->properties) - (char*)this)); }
It’s still very very clever though, and it definitely clears any lingering doubt that anything separates current C++ from properties besides the ability to get this from a nested class member function.
T& self() { return *(T*)((char*)(this) - ((char*)&(((T*)this)->properties) - (char*)this)); }
In the end I feel like there's very little interesting use-cases for properties in C++, and most of these problems could be solved with library code.
--
---
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/n0QcD_K5dBY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
size could easily iterate over a million elements. It looks like a simple assignment to an int. There would be no indication you're actually doing a ton of work.
On Tuesday, July 8, 2014 3:42:07 AM UTC-7, Klaim - Joël Lamotte wrote:
On Tue, Jul 8, 2014 at 12:23 AM, <max...@gmail.com> wrote:size could easily iterate over a million elements. It looks like a simple assignment to an int. There would be no indication you're actually doing a ton of work.
It's true for almost any abstraction and this argument can be used against any improvements.I don't consider this argument helpful to this discussion.There is a very real different between most C++ abstractions and their hidden costs and allowing properties. One example is operator->. A key bit here is that foo->bar and foo->baz will always have the same cost associated with operator->. You won't have foo->bar be cheap and foo->baz be heinously expensive. Going with the previous C# example, it's unlikely for Foo.Vertices.Count to be completely different than Foo.VertexCount from Foo's perspective in C++ since Foo.Whatever has a uniform behavior (access the member variable named Whatever in object Foo).
Yes, any abstraction can introduce hidden costs. Not all abstractions are equal, though. There's a lot of value in allowing overloads of + or * (for math types like complex, SIMD types, etc.) making the potential nonsense some users do a worthwhile risk. Likewise, some abstractions still provide clear points to watch out for, unless generic properties which allow two otherwise identical-looking constructs to have wildly different behaviors.
These two points combined, for me, damn properties. They don't actually make any difficult problems trivial and because they have low utility, their high cost is too much. From the context of C++, getters and setters work just fine. The point at which properties become important (even in C#) is during serialization and other metadata/introspection operations; that is, they're useful when interacting with external code or features and not the code itself. And then they're just an in-language syntax for grouping getters and setters in a way that easily exposes them to those introspection capabilities. However, there are other way of achieving that goal, ranging from more capable introspection that can group getters/setters, introspection with user-defined-attribute support that groups them, or markup facilities that construct a conceptual property that is used only by introspection and not C++ code itself (which is the status-quo for C++ metadata/introspection facilities today).
I would suggest that properties proponents come up with a solid set of use cases of things that you cannot do or cannot do easily in C++ today that properties would solve and try to very clearly illustrate their utility. As it stands today, I can't see any reason for properties besides "C# has them." C# has a lot of good ideas worth taking, a lot of bad ideas worth avoiding, and a lot of ideas that are just different ways of doing things and aren't worth the effort of "porting." Properties fall into the last category by every measure I can come up with personally, and almost certainly by every measure the committee and other knowledgeable C++ experts have. If you disagree, you're gonna have to prove us all wrong.
Short version: properties do not add significant value and can potentially do some harm so the benefit/cost ratio is just too low to make them worth adding to the language.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
There is a very real different between most C++ abstractions and their hidden costs and allowing properties. One example is operator->. A key bit here is that foo->bar and foo->baz will always have the same cost associated with operator->. You won't have foo->bar be cheap and foo->baz be heinously expensive. Going with the previous C# example, it's unlikely for Foo.Vertices.Count to be completely different than Foo.VertexCount from Foo's perspective in C++ since Foo.Whatever has a uniform behavior (access the member variable named Whatever in object Foo).Are you ignoring custom "smart" pointers here? Because as someone else pointed, you don't know the cost of calling ->. It totally depends on the implementation and it can change.
Yes, any abstraction can introduce hidden costs. Not all abstractions are equal, though. There's a lot of value in allowing overloads of + or * (for math types like complex, SIMD types, etc.) making the potential nonsense some users do a worthwhile risk. Likewise, some abstractions still provide clear points to watch out for, unless generic properties which allow two otherwise identical-looking constructs to have wildly different behaviors.To clarify, I'm not against properties, I think it can help in a lot of situations. However I think that focusing on the cost of an arbitrary implementation of a useful abstraction is not helpful to the discussion.Basically, it's like saying that properties (whatever the form it takes) seems useful for stabilizing interfaces with accessors, but can also be used to do some dumb stuffs, as any powerful abstraction tool.
These two points combined, for me, damn properties. They don't actually make any difficult problems trivial and because they have low utility, their high cost is too much. From the context of C++, getters and setters work just fine. The point at which properties become important (even in C#) is during serialization and other metadata/introspection operations; that is, they're useful when interacting with external code or features and not the code itself. And then they're just an in-language syntax for grouping getters and setters in a way that easily exposes them to those introspection capabilities. However, there are other way of achieving that goal, ranging from more capable introspection that can group getters/setters, introspection with user-defined-attribute support that groups them, or markup facilities that construct a conceptual property that is used only by introspection and not C++ code itself (which is the status-quo for C++ metadata/introspection facilities today).I think that introspection don't solve the main problem that properties solve: being able to switch from a public member (from a raw struct) to an accessor function, without breaking user's code.
--
---
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/n0QcD_K5dBY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
> Lets just lay it out simple. Almost every programming language under the[citation needed]. I have no trouble finding very popular languages that don't.
> sun short of C and C++ is supporting the idea of "properties". If it's such
Yes? People are trying wacky ways to support all sorts of features that
> a bad thing why is it so openly supported by most all other competing
> languages? One just needs to google "How to make C# like properties in
> C++". People are trying wacky ways to get this support by overloading the
> '=' operator and other listed here.
are available in other programming languages, and vice versa for c++
features.
Apparently many enough don't, since it has been rejected.
> If the C++ ISO committee blocks this yet again; it's not a hit to anything
> but C++. People have requested it; many want it. It does not change any of
Well, if the lack of properties is preventing some people from using c++,
> the previous support/power of C++ so really not having original support is
> just telling the community who wants them that "we" have another reason to
> stop you from wanting to using C++.
good riddance.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
Am 06.06.2014 06:23, schrieb Andrew Tomazos:
(...) A little more boilerplate and maybe a little less efficient than what the compiler could do for you (...)To me this statement is an indication that maybe language support might be worth considering, as a portable "zero cost" library solution is not possible for something that could be done with no overhead by the compiler.
I think that introspection don't solve the main problem that properties solve: being able to switch from a public member (from a raw struct) to an accessor function, without breaking user's code.
Fact is, most programs are going to run fast enough no matter what you do, because computers are fast.
Fact is, most programs are going to run fast enough no matter what you do, because computers are fast.
One of the ideas I agreed with in this discussion was: "maybe we need properties, maybe we don't. But if we want them, let's not make them second-class members with a poor library solution, let's make them a proper part of the language". That's true: nobody would be happy with "half-properties" and nobody ever found any proper way to implement them without drawbacks as a simple library feature.
--
---
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/n0QcD_K5dBY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
On 9 July 2014 10:03, David Krauss <pot...@gmail.com> wrote:Fact is, most programs are going to run fast enough no matter what you do, because computers are fast.
Fact?Maybe that is true in your particular domain, but for those of us who have to deal with latency, throughput, power consumption, etc., performance is definitely important.
Not if the target platform is slow whatever you wish from it. Not all computers are fast.I'm thinking about several cases in my experience where it's totally wrong to think that way, like most embedded software excluding smartphones.
Is there a way we can do this as a library solution?
--
--
--- You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/n0QcD_K5dBY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposals+unsubscribe@isocpp.org.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
C++ is currently a very complex language. In an attempt not to have its age show in terms of capabilities, the language carries a whole bunch of rules few people really understand. Never mind Koenig lookup, multiple inheritance constructor calling order and semantics or SFINAE. The average job candidate for senior C++ development positions doesn't know about stuff in C++ that might kill you even if you don't know about them, such as when it is dangerous to throw an exception or why is "explicit" important.Instead of the "what for" approach maybe a "why not" would make a more constructive argument.
C++ is currently a very complex language. In an attempt not to have its age show in terms of capabilities, the language carries a whole bunch of rules few people really understand. Never mind Koenig lookup, multiple inheritance constructor calling order and semantics or SFINAE.
Very few of the senior and experienced C++ candidates know the answer to those two questions. I don't recall a single confident, correct answer by anyone.
Back to your question of "why not?", the answer is "not to make the language any more complicated". If there is no good reason for a change, leave things as they are.
--
---
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/n0QcD_K5dBY/unsubscribe.
Tom Joe skrev 2014-07-12 09:11:"If there is no good reason for a change, leave things as they are."
Yes; agreed. But "no good reason" is a matter of view point.
C++ typical access-or implementation has historically been with
functions SetValue() GetValue().
Not really. How many getX and setX do you find in the standard library?
--
--- You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/n0QcD_K5dBY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposals+unsubscribe@isocpp.org.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
Am 06.06.2014 06:23, schrieb Andrew Tomazos:
> (...) A little more boilerplate and maybe a little less efficient than
> what the compiler could do for you (...)
>
To me this statement is an indication that maybe language support might
be worth considering, as a portable "zero cost" library solution is not
possible for something that could be done with no overhead by the
compiler. That being said I'm myself not sure whether properties in
general are a good idea as something that looks like an innocent member
access could be hiding an expensive operation without the user being
aware of its implication. The function call syntax at least makes the
reader aware that "something's possibly happening". And that being said
I can't remember how many times I wished I could give a member variable
public read access without having to boilerplate a getter every time.
I'm really not sure on which side of the fence I am here.
On the other hand I'm not sure that the abuse of a feature is a good argument against that feature.
As the level of abstraction increases, member functions can follow, implementing increasing levels of abstraction. However the member variables fall flat on their faces and instead of being able to carry on directly modeling the "properties" of the object, they are inadequate and we have to start using functions to represent the properties instead (getters and setters). This ends up with a disparity between low-level abstractions and high-level abstractions.
In summary, properties would allow class designers to provide clearer abstractions by removing the necessity to use member functions instead of variables to represent an abstraction's properties as the abstraction level increases. They are able to provide a clear high-level representation without forcing designers down the road of turning their class interfaces into a group of functions, where some happen to represent abstracted properties of some level, and its not clear which (some get/set functions might relate to abstracted properties, other get/set functions might not).
dog.expressHappiness()?
wouldn't
that even be better expressed as dog.IsHappy = True/False leaving the
finer details of doing anything at all up to the class definition.If B.AccountType = FreeChecking Then ....B.AccountType = FreeChecking(Enum);B.Widrawl($50);New B BankAccount($0);Call it bad practice; but I've always found it very handy to allow event triggers that are strictly related to a property/data change to happen automatically. Just as an example; who would really appreciate having to set all the fonts, size, margins etc... in menus and THEN having to remember to call Doc.ApplySettings(Struct Settings). When making a setting it seems natural to just apply it automatically and when one wants to retrieve what font is used just retrieve it. Maybe it's just a thinking method but I've always associated data structures to be part of class design and consider it the benefit of having OOP over Functional programming (No more packing around data everywhere; just keep it where functions are written to use it and ability to create any # of Storage/Functioning compartments (objects). Print MyData.ToString()I always have to laugh at these articles. While trying to prove properties are terrible they always seem to me to UN-intentionally show better their benefits.Casting - How would you internally cast a field w/o re-implementing a new API whereas if a property has a multi-type return the cast could be encapsulated by it's class definition.
Expressiondog.expressHappiness()?
wouldn't that even be better expressed as dog.IsHappy = True/False leaving the finer details of doing anything at all up to the class definition.
B.Deposit($50);
Call it bad practice; but I've always found it very handy to allow event triggers that are strictly related to a property/data change to happen automatically. Just as an example; who would really appreciate having to set all the fonts, size, margins etc... in menus and THEN having to remember to call Doc.ApplySettings(Struct Settings). When making a setting it seems natural to just apply it automatically and when one wants to retrieve what font is used just retrieve it. Maybe it's just a thinking method but I've always associated data structures to be part of class design and consider it the benefit of having OOP over Functional programming (No more packing around data everywhere; just keep it where functions are written to use it and ability to create any # of Storage/Functioning compartments (objects). Print MyData.ToString()