--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f202be10-efb5-4f1a-ab6a-18bf6ac873ee%40isocpp.org.
One of my post on stackoverflow.com was said to have its place here.
https://stackoverflow.com/questions/48915277/what-about-pseudoconst-qualifier
What do you think about my new pseudoconst qualifier ?
Expecting for your answer, (and/or possibly a job: long unemployed at the moment)
Jerome Saint-Martin,
Montrouge, France
--
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.
#include <vector>#include <iostream> #include <algorithm> #include <functional> class Vec { public : Vec () : val_ (std::vector<size_t> (1000, 0)) {} Vec (const Vec& v) : val_ (v.val_) {} //couple of const opposite methods void inc () { std::for_each (val_.begin (), val_.end (), [] (size_t&s) {++s;}); } void dec () { std::for_each (val_.begin (), val_.end (), [] (size_t&s) {--s;}); } void next2const () const { Vec v (*this); v.inc(); v.dec(); } void next2pseudoconst() { //pseudo const method inc (); dec (); } private : std::vector<size_t> val_; }; template<typename T> void crude_bench(T func, const size_t& count){ clock_t t = clock(); for(size_t i = 0; i < count; ++i){ func(); } double duration{(clock() - t) / (double)count}; std::cout << duration << " ticks per run\n"; } int main (int argc, char* argv []) { auto count = 100000ul; { Vec v; std::cout << "Copying: " << std::flush; crude_bench( std::bind([](Vec& v){ Vec other(v); }, v), count ); } { Vec v; std::cout << "next2const: " << std::flush; crude_bench( std::bind(&Vec::next2const, v), count ); } { Vec v; std::cout << "next2pseudoconst: " << std::flush; crude_bench( std::bind(&Vec::next2pseudoconst, v), count ); } return 0; }
Copying: 0.31656 ticks per run
next2const: 18.2984 ticks per run
next2pseudoconst: 18.0145 ticks per run
Further to my previous reply, I have written a rough version which should be a bit more reliable (it isn't perfect, but should suffice for the purpose of demonstration).
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/682b6197-db8a-41c1-9713-8a8492541e74%40isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC4OUEYmV5sAiBFW6N%3DffOreRbehZ2mByfwfZQK57A_-Xh9hPw%40mail.gmail.com.
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1519283315.58210.23.camel%40gmail.com.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCNYk37F3bivpoKcLLUvEwi%2BsJAn2O_DF9cP7ZfjBSjHVg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC4OUEa2Zk9Wv4YtqbT0w-sUhMqF2mZu36QhQW7e%3Dr-X2%2BasjQ%40mail.gmail.com.
A pseudo const method is a method who calls a method A at its beginning, few const methods, and then the reverse method A
The compiler may check the structure of a pseudo const is such :
-calls to methods A
-const or pseudo const calls
-calls to reverse methods A, in reverse
In the declaration of reverse methods, you may write the prototype of first method, then the prototype of the reverse method, appended with "reverse" + prototype of the original method
1) checking method A and reverse_A are actually reverse would be the work of the developer and debogger
2) I don't know
3) example, no sources. But in the compression tool I am trying to create, I am applying an elementary compression many times. To choose the best elementary compression, I would like to try it without copying the whole file, so be able to revert it, and my method of elementary compression could be pseudo const
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/27b5c95c-5b44-4089-bb14-b2d1b806093b%40isocpp.org.
pseudo const Is an indication to users : "the method should not change the object".
for reasons of performance, it's just pseudo const
pseudo const Is an indication to users : "the method should not change the object".
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUZN2CBB9knsvfSCUvy%3D%3DWSZ%3DTaROfSCpt%2B5x1JGARzi2g%40mail.gmail.com.
#include <iostream>
int main () {
size_t duration (0);
clock_t t (clock ());
std::cout << "Hello" << std::endl;
duration = (clock() - t);
std::cout << "Cout took " << duration << " ticks" << std::endl;
t = clock ();
std::cout << "Hello" << std::endl;
duration = (clock() - t);
std::cout << "Cout took " << duration << " ticks" << std::endl;
return 0;
}
Hello
Cout took 30 ticks
Hello
Cout took 2 ticks
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/79e74097-51db-443d-bfae-6570e92762af%40isocpp.org.
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.
That example shows that modifying values in an existing buffer is
faster than re-allocating a new buffer, copying data over to it,
and releasing that buffer.
#include <vector>
class Vec {
public :
Vec () : val_ (std::vector<size_t> (1000, 0)) {}
Vec (const Vec& v) : val_ (v.val_) {}
~Vec () {}
//couple of reverse methods
void inc () {
std::for_each (val_.begin (), val_.end (), [] (size_t&s) {++s;});
}
void dec () reverse inc () {
std::for_each (val_.begin (), val_.end (), [] (size_t&s) {--s;});
}
void write2 (std::ostream& os) const {
os << "val_ [2] == " << val_ [2] << std::endl;
}
void write_next2const (std::ostream& os) const {
Vec v (*this);
v.inc ();
v.write2 (os);
}
void write_next2reversible (std::ostream& os) reversible {
inc ();
write2 (os);
dec ();
}
//private :
std::vector<size_t> val_;
};
and about the "thread safe" problem, fel free to insert a muexI would not have wirte it your way, but this way (reversible and reverse part of declaration) but like this :#include <vector>
class Vec { public : Vec () : val_ (std::vector<size_t> (1000, 0)) {} Vec (const Vec& v) : val_ (v.val_) {}~Vec () {} //couple of reverse methodsvoid inc () { std::for_each (val_.begin (), val_.end (), [] (size_t&s) {++s;}); }void dec () reverse inc () {std::for_each (val_.begin (), val_.end (), [] (size_t&s) {--s;}); }
reversible is for the user. You trust compiler, why would not he trust you ?Then you lose the guarantee that the reversal is actually valid and the whole thing is pointless.
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7b216bd6-d0df-462c-909d-4fac15e8276d%40isocpp.org.
"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools" - Douglas Adams.In my experience, this is very much the case. If something is worthy of being a part of the language, it should be so in a consistent manner. A keyword is worthless if not enforceable by the compiler, especially when you get newer users trying to get around what they think is a restriction in a provided API by breaking everything they can find.
On 23 Feb 2018 20:01, <jsaintm...@gmail.com> wrote:
reversible is for the user. You trust compiler, why would not he trust you ?--Then you lose the guarantee that the reversal is actually valid and the whole thing is pointless.
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.
But you may avoid a great number of fools -if not all- placing a sign "fools : no entry".
On 23 Feb 2018 08:58, "Jérôme Saint-Martin" <jsaintm...@gmail.com> wrote:pseudo const Is an indication to users : "the method should not change the object".Const is an guarantee to users: the method does not change the object. A pseudoconst method would also have to guarantee this or the proposal wouldn't be useful at all. So, once again, come up with a way of guranteeing that a modification is reversed. A "reversible" or similar keyword would be more interesting. All it needs to do is only permit a series of commands and functions that are themselves reversible (ones that lose no information, so type limitations must be considered - see, for example, http://cpp.sh/9fet5 and http://cpp.sh/9redh ), in the same way that const only permits use of operations that are also const. Then you need something built into the language that does the reversing.This could be useful in a variety of situations. One of which would be an enforceable pseudoconst.
Another use of pseudoconst / reversible would allow to use hint to find an element in map within a pseudo const method. As far as I know,
m.insert (ihint, p) exists,
but not map.find (ihint, p)
With peudo const, you could write your pseudoconst find, like this, if you are certain -1 is not a second existing in the map, and map.erase (i) was defined as the reverse of insert (i) :
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/34d1dde0-b9fd-4565-8ebe-a1b1936ab96d%40isocpp.org.
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.
A "const" does not mean "pseudo const ". A more simple example :
class A {
public :
A () : val_ (0) {}
A (const A& a) : val_ (a.val_) {}
~A () {}
//couple of reverse methods
void inc () const {
val_++;
}
void dec () const {
val_--;
}
void write (std::ostream& os) const {
os << val_;
}
void write_nextconst (std::ostream& os) const { //const method
inc ();
write (os);
}
void write_nextpseudoconst (std::ostream& os) const { //pseudo const method
inc ();
write (os);
dec ();
}
mutable size_t val_;
};
int main (int argc, char* argv []) {
size_t duration (0);
A v;
std::cout << "\ttest write_nextconst" << std::endl;
std::cout << "before : ";
v.write (std::cout);
std::cout << " next A :";
v.write_nextconst (std::cout);
std::cout << " after : ";
v.write (std::cout);
std::cout << std::endl;
std::cout << "\ttest write_nextpseudoconst" << std::endl;
A v2;
std::cout << "before : ";
v2.write (std::cout);
std::cout << " next A : ";
v2.write_nextpseudoconst (std::cout);
std::cout << " after :";
v2.write (std::cout);
std::cout << std::endl;
return 0;
}
results :
test1
before : 0 next A :1 after : 1
test2
before : 0 next A : 1 after :0
test write_nextconst
before : 0 next A :1 after : 1
test write_nextpseudoconst
before : 0 next A : 1 after :0
Results are different :
The const method changed the mutable object permanently.
The future pseudo const method write_next leaves the object unchanged, even if it was changed during method. A oseudo const method shall call methods M, const methods, and reverse methods M in reverse order
On Thursday, March 1, 2018 at 10:57:41 AM UTC+1, Richard Hodges wrote:
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/34d1dde0-b9fd-4565-8ebe-a1b1936ab96d%40isocpp.org.
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/99ee238e-3e02-4c5a-9b01-67e463a096d2%40isocpp.org.
In this function, I am using insert instead of find, because it allows hint. Insert is not const, but the element inserted is be erased
I want this because for I must choose between different methods, the one giving the best result. I need to try all methods without changing the object (with a guarantee of the compiler : const calls M, const or pseudo const calls, reverse M calls), and then choose the method
If you have several hundreds of possibilities to try, and the object is huge, it's faster to try each, cancel it and try the next one, than to make a copy of the whole object hundreds of times
and then call the best method
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5262af56-c631-4c62-954c-1a2b90904319%40isocpp.org.
I'm not sure if I understand - is there a scenario where you would provide both a const and a pseudoconst method on a class?If it's just a matter of implementation, you know you can const-cast the this pointer into a non-const pointer so you can call mutable methods on it?
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ebc67007-559d-424d-aaeb-e92be7a615d7%40isocpp.org.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
--
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.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/67e1c1c7-2194-473b-9bfc-de4f6ffbdfd4%40isocpp.org.
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.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5e4668bb-1653-49ef-a1bb-9a74081d1cab%40isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5e4668bb-1653-49ef-a1bb-9a74081d1cab%40isocpp.org.