Monday, March 19, 2018

Digest for comp.lang.c++@googlegroups.com - 17 updates in 8 topics

Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 07:45PM +0100

> 1) Don't use "using namespace std"
 
Nonsense.
"Öö Tiib" <ootiib@hot.ee>: Mar 19 01:36PM -0700

On Monday, 19 March 2018 20:46:09 UTC+2, Bonita Montero wrote:
> > 1) Don't use "using namespace std"
 
> Nonsense.
 
When you use exclusively Spanish names in your code then clashes
with names in std will be less likely but then you should say
something like "disparates" not "nonsense".
Vir Campestris <vir.campestris@invalid.invalid>: Mar 19 11:07PM

On 19/03/2018 18:45, Bonita Montero wrote:
>> 1) Don't use "using namespace std"
 
> Nonsense.
 
He's right. Don't do it.
 
If you see std::vector you _know_ it's the normal one. If you just see
vector you don't. Especially in old code that pre-dates the STL.
 
Heck, I've been fixing some code today that has
typedef std::shared_ptr<someclass> buffer;
or such for half-a-dozen types - and that keeps me having to refer back
to check what they are.
 
Andy
Real Troll <Real.Troll@Trolls.com>: Mar 19 06:55PM -0400

Dear C++ Programmers,
 

 
The program has (mostly) been published for C++Now 2018:
 
http://cppnow.org/announcements/2018/03/2018-program-announced/
 

 
It promises to be an exciting event. It isn't too late to decide to join us in Aspen this may:
 
http://cppnow.org/registration/
 

 
Jon
computer45 <computer45@cyber.com>: Mar 19 10:06PM -0400

Hello..
 
 
To understand better my new fully scalable reference counting algorithm,
i will explain it to you:
 
I have optimized it more, now i am using only tokens and no antitokens
in the balancers of the scalable counting networks, so i am only
supporting increment, not decrement, so you have to be smart to invent
it correctly, this is what i have done, so look at the
AMInterfacedObject.pas file inside my zip file, you will notice that it
uses counting_network_next_value() function,
counting_network_next_value() increments the scalable counter network by
1, the _AddRef() method is simple, it increment by 1 to increment the
reference to the object, but look inside the _Release() method it calls
counting_network_next_value() three times, and my invention is calling
counting_network_next_value(cn1) first inside the _Release() method to
be able to make my scalable algorithm works, so just debug it more and
you will notice that my scalable algorithm is smart and it is working
correctly, i have debugged it and i think it is working correctly.
 
I have found this Scalable Reference Counting Garbage Collector, and i
think it is the only one invented by two PhDs from Israel:
 
http://www.cs.technion.ac.il/users/wwwb/Reports/1999/CS0967.pdf
 
So i have decided to invent and to implement another fully scalable
reference counting algorithm with efficient support for weak references,
it is fully scalable on multicores and manycores systems and here it is:
 
https://sites.google.com/site/aminer68/scalable-reference-counting-with-efficient-support-for-weak-references
 
Hope you will be happy with my project , because since i "love" Delphi,
i have decided to bring the "best" to Delphi, my scalable reference
counting algorithm can be ported to C++Builder or to other C++ compilers
also.
 
Thank you,
Amine Moulay Ramdane.
"Öö Tiib" <ootiib@hot.ee>: Mar 19 03:36PM -0700

On Tuesday, 20 March 2018 00:06:58 UTC+2, computer45 wrote:
> Hello..
 
You started four threads about your Delphi reference counting code.
It is not topical in comp.lang.c++

In C++ it is responsibility to standard library to implement reference
counting in most efficient manner for given platform as std::shared_ptr
and std::weak_ptr. We are not going to translate your Delphi code into
C++.
 
You have promised before not to post your off-topic posts here.
computer45 <computer45@cyber.com>: Mar 19 10:41PM -0400

On 3/19/2018 6:36 PM, Öö Tiib wrote:
> counting in most efficient manner for given platform as std::shared_ptr
> and std::weak_ptr. We are not going to translate your Delphi code into
> C++.
 
You are right.
 
But i have posted my code of my scalable algorithm, so if you need to
translate it to C++, feel free to do it.
 
> You have promised before not to post your off-topic posts here.
 
 
It was not completely of topic, because i have wanted to say to you
to translate it to C++.
 
 
 
 
Thank you,
Amine Moulay Ramdane.
computer45 <computer45@cyber.com>: Mar 19 09:48PM -0400

Hello,
 
 
To understand better my new fully scalable reference counting algorithm,
i will explain it to you:
 
I have optimized it more, now i am using only tokens and no antitokens
in the balancers of the scalable counting networks, so i am only
supporting increment, not decrement, so you have to be smart to
invent it correctly, this is what i have done, so look at
the AMInterfacedObject.pas file inside my zip file,
you will notice that it uses counting_network_next_value() function,
counting_network_next_value() increment the scalable counter network
by 1, the _AddRef() function is simple, it increment by 1 to increment
the reference to the object, but look inside the _Release() function
it calls counting_network_next_value() three times, and my invention
is calling counting_network_next_value(cn1) first inside the _Release()
function to be able to make my scalable algorithm works, so just
debug it more and you will notice that my scalable algorithm is smart
and it is working correctly, i have debugged it and i think it is
working correctly.
 
 
About scalable reference counting..
 
I have found this Scalable Reference Counting Garbage Collector, and i
think it is the only one invented by two PhDs from Israel:
 
http://www.cs.technion.ac.il/users/wwwb/Reports/1999/CS0967.pdf
 
 
So i have decided to invent and to implement another fully scalable
reference counting algorithm with efficient support for weak references,
it is fully scalable on multicores and manycores systems and here it is:
 
https://sites.google.com/site/aminer68/scalable-reference-counting-with-efficient-support-for-weak-references
 
Hope you will be happy with my project , because since i "love" Delphi,
i have decided to bring the "best" to Delphi, my scalable reference
counting algorithm can be ported to C++Builder or to other C++ compilers
also.
 
 
Thank you,
Amine Moulay Ramdane.
computer45 <computer45@cyber.com>: Mar 19 09:20PM -0400

Hello..
 
About scalable reference counting..
 
I have found this Scalable Reference Counting Garbage Collector, and i
think it is the only one invented by two PhDs from Israel:
 
http://www.cs.technion.ac.il/users/wwwb/Reports/1999/CS0967.pdf
 
 
So i have decided to invent and to implement another fully scalable
reference counting algorithm with efficient support for weak references,
it is fully scalable on multicores and manycores systems and here it is:
 
https://sites.google.com/site/aminer68/scalable-reference-counting-with-efficient-support-for-weak-references
 
Hope you will be happy with my project , because since i "love" Delphi,
i have decided to bring the "best" to Delphi, my scalable reference
counting algorithm can be ported to C++Builder or to other C++ compilers
also.
 
 
Thank you,
Amine Moulay Ramdane.
computer45 <computer45@cyber.com>: Mar 19 09:20PM -0400

Hello..
 
About scalable reference counting..
 
I have found this Scalable Reference Counting Garbage Collector, and i
think it is the only one invented by two PhDs from Israel:
 
http://www.cs.technion.ac.il/users/wwwb/Reports/1999/CS0967.pdf
 
 
So i have decided to invent and to implement another fully scalable
reference counting algorithm with efficient support for weak references,
it is fully scalable on multicores and manycores systems and here it is:
 
https://sites.google.com/site/aminer68/scalable-reference-counting-with-efficient-support-for-weak-references
 
Hope you will be happy with my project , because since i "love" Delphi,
i have decided to bring the "best" to Delphi, my salable reference
counting algorithm can be ported to C++Builder or to other C++ compilers
also.
 
 
Thank you,
Amine Moulay Ramdane.
Lynn McGuire <lynnmcguire5@gmail.com>: Mar 19 02:40PM -0500

> Looking for some example of stellar code for educational purpose. Any recommendations?
 
100 lines ?
 
100,000 lines ?
 
10,000,000 lines ?
 
Lynn
"Öö Tiib" <ootiib@hot.ee>: Mar 19 02:17PM -0700

> Looking for some example of stellar code for educational purpose. Any recommendations?
 
If by "stellar" you mean "simple" && "efficient" && "elegant" && "readable"
&& "flexible" && "solid" && "clear" && "robust", then there may be are such
things but those are rare.
 
Of course everything should be done as simply as possible but not simpler
than possible. Majority of problems worth solving do not have simple
solutions. Only about 5% of code base is worth considering from viewpoint
of efficiency, rest just should avoid being too feeble. About 80% of useful
code base is checking pre-conditions and post-conditions and handling
errors and corner cases. As such it can be plain and robust but not too
elegant. The flexible and solid are also sort of contradicting with each
other.
 
So what remains ... readability, clarity and robustness. These are worth
teaching ... rest are rare luxury in practice.
Christiano <christiano@engineer.com>: Mar 18 11:27PM -0300

Lippman 5th
ISBN-13: 978-0321714114
 
Page 280-281, it says:
 
Begin
{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
 
*Making A Member Function a Friend*
 
Rather than making the entire Window_mgr class a friend, Screen can
instead specify that only the clear member is allowed access. When we
declare a member function to be a friend, we must specify the class of
which that function is a member:
 
class Screen {
// Window_mgr::clear must have been declared before class Screen
friend void Window_mgr::clear(ScreenIndex);
// ... rest of the Screen class
};
 
Making a member function a friend requires careful structuring of our
programs to accommodate interdependencies among the declarations and
definitions. In this example, we must order our program as follows:
• First, define the Window_mgr class, which declares, but cannot define,
clear. Screen must be declared before clear can use the members of Screen.
• Next, define class Screen, including a friend declaration for clear.
• Finally, define clear, which can now refer to the members in Screen.
 
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
End
 
The problem is: class Window_mgr has a data member that depends of class
Screen definition. See:
 
class Window_mgr {
public:
// location ID for each screen on the window
using ScreenIndex = std::vector<Screen>::size_type;
// reset the Screen at the given position to all blanks
void clear(ScreenIndex);
private:
std::vector<Screen> screens{Screen(24, 80, ' ')};
};
 
So it is impossible firstly define Window_mgr without defining Screen
previously!
And at the same time, it is impossible define Screen without we have
defined Window_mgr!!!
 
How can this problem be solved???
Is the book wrong?
 
I will paste here a code so that you can repeat the problem using a
minimal code:
 
///////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
 
class A
{
friend void B::hello();
 
public:
A(int i) : number{i} {}
 
private:
void f() {
std::cout << "hello" << std::endl;
}
int number;
};
 
class B {
private:
std::vector<A> x{A(10)};
 
public:
void hello()
{
for(A &elem : x)
{
elem.f();
}
}
};
 
 
int main()
{
A x;
 
return 0;
}
 
///////////////////////////////////////
 
If I compile this code, the result is:
error: use of undeclared identifier 'B'
friend void B::hello();
 
And if I invert the position (A <--> B), I have:
error: use of undeclared identifier 'A'
std::vector<A> x{A(10)};
 
 
Is there a correct way to do that??
 
Thank you!
Daniel <danielaparker@gmail.com>: Mar 18 07:46PM -0700

On Sunday, March 18, 2018 at 7:36:16 PM UTC-4, Christiano wrote:
> error: use of undeclared identifier 'A'
> std::vector<A> x{A(10)};
 
> Is there a correct way to do that??
 
To write
 
friend void B::hello();
 
B would need to be a complete type, a forward declaration for B wouldn't do.
 
But I suppose you could do something like this:
 
template <class T>
class A
{
friend void typename T::hello();
 
public:
A(int i) : number{ i } {}
 
private:
void f() {
std::cout << "hello" << std::endl;
}
int number;
};
 
class B {
private:
std::vector<A<B>> x{ A<B>(10) };
 
public:
void hello()
{
for (A<B> &elem : x)
{
elem.f();
}
}
};
 
int main()
{
A<B> x(1);
 
return 0;
}
 
Daniel
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 19 06:57AM +0100

On 19.03.2018 03:27, Christiano wrote:
> And at the same time, it is impossible define Screen without we have
> defined Window_mgr!!!
 
> How can this problem be solved???
 
For example as shown below.
 
 
> Is the book wrong?
 
Yes.
 
 
----------------------------------------------------------------------------
#include <stddef.h>
#include <vector>
 
using ScreenIndex = ptrdiff_t; // Not the silly
`std::vector<Screen>::size_type`
class Screen;
 
namespace window_mgr_screen_ops
{
void clear( Screen& );
};
 
class Screen
{
friend void window_mgr_screen_ops::clear( Screen& );
// ... rest of the Screen class
 
public:
Screen( int, int, char );
};
 
class Window_mgr
{
std::vector<Screen> screens{ Screen{ 24, 80, ' ' } };
 
public:
// reset the Screen at the given position to all blanks
void clear( ScreenIndex const i )
{
window_mgr_screen_ops::clear( screens[i] );
}
};
----------------------------------------------------------------------------
 
 
Cheers & hth.,
 
- Alf
Christiano <christiano@engineer.com>: Mar 19 08:10AM -0300

On 03/19/18 02:57, Alf P. Steinbach wrote:
> ----------------------------------------------------------------------------
 
> Cheers & hth.,
 
> - Alf
 
Solution:
 
#include <iostream>
#include <string>
#include <vector>
 
class A;
 
class B {
private:
std::vector<A> x;
 
public:
B();
void hello();
 
};
 
class A
{
friend void B::hello();
 
public:
A(int i) : number{i} {}
 
private:
void f() {
std::cout << "hello" << std::endl;
}
int number;
};
 
B::B() : x{A(10)}
{
 
}
 
void B::hello()
{
for(A &elem : x)
{
elem.f();
}
}
 
int main()
{
 
 
return 0;
}
 
Conclusions about the book is wrong or not:
 
1- The book omits the necessity of firstly add a forward declaration of
class A .
2- The book omits that It is not possible to do in-class initialization
inside class B because class A must be incomplete (forward declaration)
at the time that class B is being defined.
 
Interesting facts:
 
1- vector<A> inside class B is not a problem (as long as A has been
forward-declared above)
2- A(10) inside class B is a problem because it is creating a object
with type A, which was not completely defined at that moment
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 19 12:38PM +0100

On 19.03.2018 12:10, Christiano wrote:
 
> class B {
> private:
>     std::vector<A> x;
 
A vector with items of incomplete type is permitted as of C++17.
 
It's worth being aware that that was not previously supported, i.e. this
code targets C++17 and above.
 
See <url:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4371.html>.
 
 
 
 
> Interesting facts:
 
> 1- vector<A> inside class B is not a problem (as long as A has been
> forward-declared above)
 
See note above.
 
 
> 2- A(10) inside class B is a problem because it is creating a object
> with type A, which was not completely defined at that moment
 
 
Cheers & hth.,
 
- Alf
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: