- didactics of reference parameters[Supersedes] - 1 Update
- Constructing const array out of constexpr function - 5 Updates
- polymorph? - 5 Updates
- OT: Association for Orthodox Jewish Scientists - 2 Updates
- interface for backward compatibility? - 3 Updates
- Inheritance-type enum - 3 Updates
- "Q&A: Bjarne Stroustrup previews C++ 17" - 1 Update
Ian Collins <ian-news@hotmail.com>: Mar 21 12:13PM +1300 >> /Flibble > I don't do that to be annoying. I do it because it's > the responsible thing to do. No it isn't. No sane developer would create their own top level namespace called "std". -- Ian Collins |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 20 05:47AM +0100 On 19.03.2016 00:18, bitrex wrote: > { > return std::pow(x, 2); > } As Öö Tiib have remarked else-thread, "Almost none of the [standard library's] math functions can be 'constexpr', since these contain the legacy requiment of setting 'errno' on various error conditions, on case of 'pow' it is 'EDOM' AFAIK.". So the above code just can't be supposed: it's not possible. But let's suppose static constexpr auto square( int x ) -> int { return x*x; } > //something > }; > What is the "proper" way to do this? You'd have to define "proper". :) Anyway, the following code works with Visual C++ 2015 update 2 and MinGW g++ 5.1.0: #include <array> // std::array #include <stddef.h> // size_t #include <utility> // std::index_sequence static constexpr auto square( int x ) -> int { return x*x; } class Squares { public: enum{ n = 256 }; using Array = std::array<int, n>; private: Array values_; template< size_t... index > constexpr Squares( std::index_sequence<index...> ) : values_{ {square(index)...} } {} public: constexpr auto values() const -> std::array<int, n> const& { return values_; } constexpr Squares() : Squares( std::make_index_sequence<n>() ) {} }; #include <iostream> auto main() -> int { constexpr Squares squares; char a[squares.values()[42]]; using namespace std; cout << sizeof( a ) << endl; (void) a; } Cheers & hth., - Alf |
Robert Wessel <robertwessel2@yahoo.com>: Mar 20 03:05PM -0500 On Sat, 19 Mar 2016 09:03:52 -0400, bitrex >> /Jorgen >Just for the purposes of illustration. In my actual code, I'll need to >use a moderately complicated equation involving e^x... Out of curiosity, what's the range and precision of x that you need to support (including things like NaNs, zeros and Infs), and what precision can you live with in the result? It would be possible to construct a constexpr function that would evaluate a limited range of e**x, although doing it well (FSVO "well") would be a challenge. Something evaluating the standard Taylor series (1+x+x**2/2!+x**3/3!...), vaguely like: #include <iostream> #define LIMIT 1000000. constexpr double exp_w(double x, double x2, double d, double d2) { return ((d2/x2)>LIMIT) ? 0 : (x2/d2 + exp_w(x, x*x2, d+1, d2*d)); } constexpr double exp(double x) { return x<0 ? 1/exp_w(-x, 1, 1, 1) : exp_w(x, 1, 1, 1); } inline void test(double x) { double t; t=exp(x); std::cout << "e**" << x << " = " << t << std::endl; } int main(void) { test(0); test(1); test(1.5); test(2); test(3.14); test(42); test(-1); test(-3.14); test(19.4); } Which produces the following for me: e**0 = 1 e**1 = 2.71828 e**1.5 = 4.48169 e**2 = 7.38906 e**3.14 = 23.1039 e**42 = 1.73927e+18 e**-1 = 0.367879 e**-3.14 = 0.0432828 e**19.4 = 2.66264e+08 LIMIT should be chosen to generate the required accuracy in the desired range. It should be about the maximum precision of a double (~2**53), at that point the last term will contribute less than an ULP to the sum. Assume that the error will be about an ULP per term evaluated of the Taylor series, which in the worst case* should be about 200 ULPs**, although most values will produce rather less error than that. This will probably do poorly if the result overflows, or a NaN or Inf is input. Those limitations could all be improved, but it would be a bit messy. *That should occur where x is somewhere in the vicinity of (200!)**(1/200) **And in practice some of the errors should be in opposite directions, but I've not done the analysis. |
Juha Nieminen <nospam@thanks.invalid>: Mar 20 08:50PM > : Squares( std::make_index_sequence<n>() ) > {} > }; I'm not exactly sure why you are using a class here. Or why you are using an enum. --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
"Öö Tiib" <ootiib@hot.ee>: Mar 20 03:07PM -0700 On Sunday, 20 March 2016 22:50:35 UTC+2, Juha Nieminen wrote: > > }; > I'm not exactly sure why you are using a class here. Or why you are > using an enum. How else to make delegating, constexpr, variadic, template constructor if not by having a class? Follows ... why to make that thing? Not sure. Perhaps for trying out where those actually run and how. 2 years old standard must have some mature enough implementations for usage. I can't use it in over half of code-bases because of tooling but it will change with years. |
Robert Wessel <robertwessel2@yahoo.com>: Mar 20 05:18PM -0500 On Sun, 20 Mar 2016 15:05:57 -0500, Robert Wessel >((d2/x2)>LIMIT) The first conditional would be better coded as: ((x2/d2)<(1/LIMIT)) Since x2 can go to zero. |
Jens Kallup <jkallup@web.de>: Mar 20 12:01PM +0100 Hello, How can I create a C++ structure of classes: Shape | PositionOfShape / \ Rectangle Circle \ / Properties - Color - Brush... I think each class (Rectangle, and Circle) have same standard properties. Can i specialize it in sub class? Like radius of Circle, and radius of borders circle (as example)? Is it possible to iterate through Shape to know how many objects are present? TIA Jens |
Victor Bazarov <v.bazarov@comcast.invalid>: Mar 20 09:08AM -0400 On 3/20/2016 7:01 AM, Jens Kallup wrote: > circle (as example)? > Is it possible to iterate through Shape to know > how many objects are present? We don't do somebody else's assignments or homework here. Here is a hint for you: look into virtual inheritance. Keyword: diamond pattern. V -- I do not respond to top-posted replies, please don't ask |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Mar 20 05:36PM On 20/03/2016 13:08, Victor Bazarov wrote: >> how many objects are present? > We don't do somebody else's assignments or homework here. Here is a > hint for you: look into virtual inheritance. Keyword: diamond pattern. Try again Victor: virtual inheritance is NOT appropriate here. /Flibble |
"Öö Tiib" <ootiib@hot.ee>: Mar 20 01:24PM -0700 On Sunday, 20 March 2016 13:01:16 UTC+2, Jens Kallup wrote: > - Brush... > I think each class (Rectangle, and Circle) have > same standard properties. What book you read about object oriented design? > Can i specialize it in sub class? If you think that Rectangle and Circle have common properties then it is likely because one of such cases: * Rectangle is always Circle too. * Circle is always Rectangle too. * Rectangle and Circle are always DrawnThingies and the common properties are those of DrawnThingy. * Rectangle and Circle have some common to both component DrawingTools. There are no way out of that puzzle without brain power applied. Common sub-class does not help you. It is for complex cases when it happens that something is fully both Circle and Rectangle. For example RectangularCircle. Does RectangularCircle make sense? > Like radius of Circle, and radius of borders > circle (as example)? What? Try with full sentence. I attempted to combine it in various ways with previous sentences ... but radius does make no sense about Rectangle to me, sorry. > Is it possible to iterate through Shape to know > how many objects are present? If programmer (or some defect made by programmer) makes it possible then it is possible. Some things are just little bit more expensive to implement than others. So start with basics, what objects the Shape consists of? Why you want to implement iterating over those? |
Juha Nieminen <nospam@thanks.invalid>: Mar 20 08:54PM > Can i specialize it in sub class? > Like radius of Circle, and radius of borders > circle (as example)? If Rectangle and Circle have common properties, then they go into a common base class. That's object-oriented design 101. > Is it possible to iterate through Shape to know > how many objects are present? I think you have a misunderstanding of what "class" and "object" mean in C++. (They don't necessarily have the same meaning as in other object-oriented languages.) --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
"Öö Tiib" <ootiib@hot.ee>: Mar 19 05:23PM -0700 On Saturday, 19 March 2016 23:57:21 UTC+2, Mr Flibble wrote: > Jesus of Nazareth never actually existed though. Some historical person > that Jesus might have been partially based on and Jesus are not the same > individual. I wrote that I believe only part of it. That there was a rabbi, son of carpenter who did teach such unusual altruist ethics to his followers and was executed because of Jewish priests, lawyers and political leaders did not like him. That is rather similar to story of Giordano Bruno who did teach free philosophical and scientific thought and who was executed because of Italian priests, lawyers and political leaders did not like him. Especially remarkable is that on case of Giordano Bruno those were "Christian" priests, lawyers and political leaders. > But this has very little to do with C++ and just feeds the trolls so I > will stop. I agree, but I do not think that Brian is troll. He just likely does not understand that in comp.lang.c++ it is impossible to become a martyr. Here are no priests, lawyers nor political leaders to execute him. All he can achieve here is being nutjob Don Quixote and to do wrong things and to fight with his imaginary giants and windmills. |
Juha Nieminen <nospam@thanks.invalid>: Mar 20 08:40PM > Years ago I worked at IBM, American Express and You are complete deflecting and avoiding everything I have written and asked. You are more deeply self-brainwashed that I would have thought. You can't even have a straight, honest conversation. --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
Jens Kallup <jkallup@web.de>: Mar 20 11:49AM +0100 Hello, like the topic says: Is it possible? And when, how? Under Linux Debian Jessie 8.0 gcc 4.9? TIA Jens |
Victor Bazarov <v.bazarov@comcast.invalid>: Mar 20 09:11AM -0400 On 3/20/2016 6:49 AM, Jens Kallup wrote: > like the topic says: Is it possible? > And when, how? > Under Linux Debian Jessie 8.0 gcc 4.9? Not sure exactly what you mean by your subject or your questions. Anything is possible, generally speaking, it's usually the matter of time and effort. As to "when and how", the former is for you to decide and the latter is in the details which you didn't supply. V -- I do not respond to top-posted replies, please don't ask |
"Öö Tiib" <ootiib@hot.ee>: Mar 20 12:29PM -0700 On Sunday, 20 March 2016 12:49:50 UTC+2, Jens Kallup wrote: > like the topic says: Is it possible? > And when, how? > Under Linux Debian Jessie 8.0 gcc 4.9? Define "interface for backward compatibility". For what? By whom? Do you mean C++ ABI? Backward compatibility is never impossible but we can't communicate about it with telepathy. |
JiiPee <no@notvalid.com>: Mar 20 12:48AM On 19/03/2016 21:29, Öö Tiib wrote: > Oh then it seems I understood you correctly. If you want compile-time > diagnostics then neither 'enum animal_type' nor 'std::type_info' can help > you so you are in deep confusion. Tiib... but please... :). You know, as an experienced programmer, well that enum *does not* accecpt for example an integer! so why you say that? for example: void foo(Animal animal) { if (animal == Animal::Elephant) cout << "was elephant"; } will give an compile timer error if you call it with: foo(3); ! dont you agree? |
"Öö Tiib" <ootiib@hot.ee>: Mar 20 02:09AM -0700 On Sunday, 20 March 2016 02:48:39 UTC+2, JiiPee wrote: > will give an compile timer error if you call it with: > foo(3); > ! dont you agree? Yes I do. But the 'foo((Animal)3)' call feels as pointless as 'foo(Animal::Ape)'. Typical use case of such id value is when it is dynamically taken from elsewhere, for example read as byte (or bytes) from somewhere: char value; some_file.read(&value, 1); Animal creature = (Animal)value; foo(creature); As result there won't be any compile-time checks made. |
Jens Kallup <jkallup@web.de>: Mar 20 11:14AM +0100 What is the heck? Try this: #include <iostream.h> typedef enum { idOfAnimalUnknown = 0, idOfAnimalCat = 1, idOfAnimalDog = 2, idOfAnimalElephant = 3 } Animal; class MyAnimals { public: MyAnimals(Animal what) { _animal = what; } protected: Animal _animal; }; int main(void) { MyAnimals animal1(idOfAnimalDog); MyAnimals * animal2 = new MyAnimals(idOfAnimalCat); if (animal1._animal == idOfAnimalDog) std::cout << "animal is a dog" << std::endl; switch (animal2->_animal) { case idAnimalCat: { std::cout << "it's a cat" << std::endl; } break; default: std::cout << "unknown" << std::endl; break; } delete animal2; return 0; } cheers Jens |
woodbrian77@gmail.com: Mar 19 06:44PM -0700 On Friday, March 18, 2016 at 9:31:56 PM UTC-5, Lynn McGuire wrote: > future upgrade" > I thought Infoworld was dead. > Lynn It's bad news and he tries to sugarcoat it, but I'm glad they aren't going to let the schedule slip. If I remember correctly, the 2017 release was supposed to be a major release. With 2011 being a major release and 2014 being minor. Bjarne says, "For some, optional, any, and string_view from the Library Fundamentals will be significant." I don't think any is needed. There's already some junk in the standard, and I'd rather not add to it. Brian Ebenezer Enterprises - "The fear of the L-rd is the beginning of wisdom." Proverbs 9:10 http://webEbenezer.net |
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:
Post a Comment