- Restricting a class to dynamic instantiation via destructor access -- what about smart pointers? - 2 Updates
- Christmas is about Jesus Christ (Savior of the world) - 3 Updates
- Merry Festivus - 3 Updates
- Reworking exception class - 1 Update
- My C++ Coding Standards ( apologies to Bjarne Stroustrup ). - 3 Updates
- Restricting a class to dynamic instantiation via destructor access -- what about smart pointers? - 1 Update
ram@zedat.fu-berlin.de (Stefan Ram): Dec 24 04:10AM >For a restriction to dynamic allocation by making the destructor >non-`public`, I wonder what would be a good way to support destructor >invocation via `std::shared_ptr` and other smart pointers? My quick take at it; I am not restricting the access to the destructor, but to the constructor. #include <iostream> #include <new> #include <memory> class dynamic_only { int x_; explicit dynamic_only( int const x ): x_{ x } {} public: int x() const { return x_; } template< typename... Args > static ::dynamic_only * make_new( Args && ... args ) { return new ::dynamic_only( ::std::forward< Args >( args )... ); } template< typename... Args > static ::std::unique_ptr< dynamic_only > make_unique( Args && ... args ) { return ::std::unique_ptr< dynamic_only > ( new ::dynamic_only( ::std::forward< Args >( args )... )); }}; int main() { // ::dynamic_only d( 2 ); // error: 'dynamic_only( int )' is private ::dynamic_only * const do0 = ::dynamic_only::make_new( 2 ); ::std::unique_ptr< ::dynamic_only > do1 = ::dynamic_only::make_unique( 2 ); ::std::clog << do0->x() << '\n'; ::std::clog << do1->x() << '\n'; ::delete( do0 ); /* do0 is not managed exception-safely here */ } |
ram@zedat.fu-berlin.de (Stefan Ram): Dec 24 10:55PM >My quick take at it; I am not restricting the access >to the destructor, but to the constructor. A slightly modified version: #include <iostream> #include <new> #include <memory> template< class T > struct dynamic_only_support { template< typename... Args > static T * make_new( Args && ... args ) { return new T( ::std::forward< Args >( args )... ); } template< typename... Args > static ::std::unique_ptr< T > make_unique( Args && ... args ) { return ::std::unique_ptr< T > ( new T( ::std::forward< Args >( args )... )); } }; class dynamic_only : public dynamic_only_support < dynamic_only > { friend struct dynamic_only_support < dynamic_only >; int x_; explicit dynamic_only( int const x ): x_{ x } {} public: int x() const { return x_; }}; int main() { /* ::dynamic_only d; */ /* error */ /* ::dynamic_only d( 2 ); */ /* error */ auto const dp0 = ::dynamic_only::make_unique( 2 ); auto const dp1 = ::dynamic_only::make_new( 2 ); ::std::clog << dp0->x() << '\n'; ::std::clog << dp1->x() << '\n'; ::delete( dp1 ); /* dp1 is not managed exception-safely here */ } |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 24 12:02PM -0800 Why do I worship Jesus Christ as Lord and Savior? Because I've sought the matter out and I've come to know that Jesus is not the actions of sinful men doing things in His name, but rather He is separate and isolated, called even, "Holy, Holy, Holy" (three times) in scripture. Jesus is not the actions of sinful men, and their domineering spirit lording over people their power, their will. He is freedom from all of that, and it is personal ... between you and Him. It's not between you and a church, you and a priest, you and anything else. It is that which is between you and Him. The person you look at in the mirror, and Him. He will forgive you of your sin and give you eternal life. All you have to do is repent of your sin and ask Him. He could not have made it any easier and still give you a choice. Go to a Christmas service this evening. Learn about the true meaning of Christmas. You'll hear about how the night skies opened up and the light shone all around and a chorus of speaking angels appeared to men to announce His birth. The shepherds left the flocks they were attending by night and went to seek the one whose birth was so announced (by such a vast array of Heavenly Hosts). http://biblehub.com/kjv/luke/2.htm The Shepherds and Angels 8 And there were in the same country shepherds abiding in the field, keeping watch over their flock by night. 9 And, lo, the angel of the Lord came upon them, and the glory of the Lord shone round about them: and they were sore afraid. 10 And the angel said unto them, Fear not: for, behold, I bring you good tidings of great joy, which shall be to all people. 11 For unto you is born this day in the city of David a Saviour, which is Christ the Lord. 12 And this shall be a sign unto you; Ye shall find the babe wrapped in swaddling clothes, lying in a manger. 13 And suddenly there was with the angel a multitude of the heavenly host praising God, and saying, 14 Glory to God in the highest, and on earth peace, good will toward men. Note: Peace on Earth through Jesus Christ. And "good will" toward men. 15 And it came to pass, as the angels were gone away from them into heaven, the shepherds said one to another, Let us now go even unto Bethlehem, and see this thing which is come to pass, which the Lord hath made known unto us. 16 And they came with haste, and found Mary, and Joseph, and the babe lying in a manger. 17 And when they had seen it, they made known abroad the saying which was told them concerning this child. 18 And all they that heard it wondered at those things which were told them by the shepherds. 19 But Mary kept all these things, and pondered them in her heart. 20 And the shepherds returned, glorifying and praising God for all the things that they had heard and seen, as it was told unto them. We do not have peace on Earth today because men follow the enemy of God rather than God. God has already made peace with man and man's sin through Jesus Christ's atoning death at the cross, His burial, and His resurrection from the dead. The good news is: Peace between God and man has come, through the man Jesus Christ. He ALONE holds the key to your eternal salvation, the ability to save your everlasting soul from death. Best regards, Rick C. Hodgin |
"Chris M. Thomasson" <invalid@invalid.invalid>: Dec 24 01:39PM -0800 On 12/24/2016 12:02 PM, Rick C. Hodgin wrote: > Why do I worship Jesus Christ as Lord and Savior? Because I've sought [...] Feliz Navidad! |
ruben safir <ruben@mrbrklyn.com>: Dec 24 05:37PM -0500 On 12/24/2016 04:39 PM, Chris M. Thomasson wrote: >> Why do I worship Jesus Christ as Lord and Savior? Because I've sought > [...] > Feliz Navidad! I seriously dislike Christians and consider them a threat to my family. They have killed Jews since their inception and nothing changes. They are all going straight to hell for their false prophecy, and they are too idiotic to know it. They are evil to the core, and pollute everything they are involved with with evangelizing. Troll a tech news group is just another form of intimidating Jews from participating in social circles. It is disgusting and ugly. |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Dec 24 04:28PM On Fri, 23 Dec 2016 22:31:13 +0000 > Perhaps you think I was alluding to your culture? I was certainly > making an assumption that you are a follower of an Abrahamic religion > (a good bet usually for someone with such an Anglo-Saxon name). Except that both 'Gareth' and 'Owen' come from Welsh. |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Dec 24 05:12PM On 24/12/2016 16:28, Chris Vine wrote: >> making an assumption that you are a follower of an Abrahamic religion >> (a good bet usually for someone with such an Anglo-Saxon name). > Except that both 'Gareth' and 'Owen' come from Welsh. All the same. /Flibble |
"Chris M. Thomasson" <invalid@invalid.invalid>: Dec 24 01:41PM -0800 On 12/23/2016 9:07 AM, Mr Flibble wrote: > Hi, > Merry festivus. I hope everyone has an enjoyable winterval. Sausages. https://en.wikipedia.org/wiki/Festivus#/media/File:Festivus_Pole.jpg ;^D |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Dec 24 04:44PM On Fri, 23 Dec 2016 13:00:28 -0800 (PST) > wrote: > > ::std::exception > The leading :: is annoying As is the gratuitous removal of whitespace in his code. > That will still give you a copy construction. Perhaps you meant > explicit failure (std::string&& > w):whatStr(std::forward<std::string&&>(w)) {} His copy constructor is certainly highly broken because with his version of it he can bind neither an rvalue nor a const lvalue to it. However, assuming he wants a move constructor, this would be a more obvious, or at least shorter, way of doing it: explicit failure (std::string&& w): whatStr(std::move(w)) {} Chris |
Jeff-Relf.Me <@.>: Dec 23 05:06PM -0800 |
Paavo Helde <myfirstname@osa.pri.ee>: Dec 24 11:00AM +0200 On 24.12.2016 3:06, Jeff-Relf.Me wrote: > ( 0, 1 ) ( 1, 1 ) ( 2, 1 ) ( 3, 1 ) > ( 0, 2 ) ( 1, 2 ) ( 2, 2 ) ( 3, 2 ) > See X.CPP in "Jeff-Relf.Me/X.ZIP". Nice. One suggestion: you should consider adding templates into your toolkit. A creative mix of macros and templates makes the code even more impenetrable. Your _Loop macros could be probably upgraded to use recursive templates instead of boring while cycles, for example! |
Peter Köhlmann <peter-koehlmann@t-online.de>: Dec 24 10:40AM +0100 wrote: > My C++ Coding Standards ( apologies to Bjarne Stroustrup ): Yes, we know. Shitty beyond belief |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Dec 24 04:00AM +0100 For a restriction to dynamic allocation by making the destructor non-`public`, I wonder what would be a good way to support destructor invocation via `std::shared_ptr` and other smart pointers? [code] #include <type_traits> #include <iostream> using namespace std; #define STATIC_ASSERT( e ) static_assert( e, "`" #e "` <-- must be true" ) namespace cppx{ template< class Type > constexpr auto is_destructible() -> bool { return std::is_destructible<Type>::value; } } // namespace cppx template< class Derived > struct Dynamic_only { void selfdestroy() { delete this; } virtual ~Dynamic_only() {} Dynamic_only() { using cppx::is_destructible; STATIC_ASSERT( not is_destructible<Derived>() ); } }; struct S: Dynamic_only<S> {}; class T: public Dynamic_only<T> { private: ~T(){} }; class U: public Dynamic_only<U>{ protected: ~U(){} }; auto main() -> int { #ifdef TEST_INSTANTIATION new S{}; new T{}; new U{};
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment