- nullptr vs. NULL - 6 Updates
- Deduce an integer from a template parameter - 3 Updates
- cmsg cancel <10aa22b1-a60d-4aa3-bf89-a8cb28dae27e@googlegroups.com> - 2 Updates
- Adaptive Function Object - 3 Updates
- CIVIL HERO AND STOCKS, COMMODITIES, CURRENCIES GENIUS MICHELE NISTA MICHELENISTA@GMX.COM! HE GET IT RIGHT ON WORLDWIDE SECURITIES, DE FACTO, ALWAYS! BOUT 6000 PREDICTIONS ON INTERNET SINCE 9.2007: 6000 SUCCESS! 100% SHOCKING WINNING SCORE! "PODEMOS"! - 1 Update
- How to define a class which looks like an array? - 10 Updates
Victor Bazarov <v.bazarov@comcast.invalid>: May 26 07:47AM -0400 On 5/22/2015 7:41 PM, Öö Tiib wrote: > it is interger zero or std::nullptr_t. >> I think those GNU folks want to be clever, and often overdo it. > They likely picked std::nullptr_t. Either way, if it's 'nullptr_t', it should pick foo(int*), if it's 'int', it should pick 'foo(int)', in both cases the other one requires a conversion of lower rank, if my reading is correct. If that is so, then it still should not be ambiguous. Now, the bad thing about picking 'nullptr_t' instead of 'int' would be that the code that used to lead to calling 'foo(int)' could now be calling 'foo(int*)' *silently*. Unless I am mistaken in reading the relevant chapter 4 and chapter 13 parts... In that case, please enlighten me. V -- I do not respond to top-posted replies, please don't ask |
Luca Risolia <luca.risolia@linux-projects.org>: May 26 05:26PM +0200 On 26/05/2015 13:47, Victor Bazarov wrote: > Either way, if it's 'nullptr_t', it should pick foo(int*) std::nullptr_t is defined as decltype(nullptr). If NULL is of type std::nullptr_t, then the first choice for foo(NULL) should be foo(std::nullptr_t), while both foo(int*) and foo(int) should be a second choice. |
Victor Bazarov <v.bazarov@comcast.invalid>: May 26 11:56AM -0400 On 5/26/2015 11:26 AM, Luca Risolia wrote: > std::nullptr_t, then the first choice for foo(NULL) should be > foo(std::nullptr_t), while both foo(int*) and foo(int) should be a > second choice. What if there is no foo(std::nullptr_t)? Does conversion from nullptr_t to int* has the same rank as conversion from nullptr_t to int? V -- I do not respond to top-posted replies, please don't ask |
Luca Risolia <luca.risolia@linux-projects.org>: May 26 07:41PM +0200 Il 26/05/2015 17:56, Victor Bazarov ha scritto: >> second choice. > What if there is no foo(std::nullptr_t)? Does conversion from nullptr_t > to int* has the same rank as conversion from nullptr_t to int? std::nullptr_t cannot be converted to int, but can be implicitly converted to int* (and to any raw pointer types). So I was imprecise in the second part of my statement: foo(int) is not an option at all if NULL is of type std::nullptr_t. To answer your question then, if there's no foo(std::nullptr_t), then the only valid option would be foo(int*). Ergo in some C++11 implementations (like mine), which complain about ambiguities in the foo(NULL) call, NULL is not of type std::nullptr_t. |
Victor Bazarov <v.bazarov@comcast.invalid>: May 26 03:50PM -0400 On 5/26/2015 1:41 PM, Luca Risolia wrote: > no foo(std::nullptr_t), then the only valid option would be foo(int*). > Ergo in some C++11 implementations (like mine), which complain about > ambiguities in the foo(NULL) call, NULL is not of type std::nullptr_t. If we go back to the earlier post of yours: On 5/22/2015 4:54 PM, Luca Risolia wrote: > [..] The above code does not compile on my C++ > implementation because the overload is really ambiguous. Doesn't what you've just written mean that the your C++ implementation is defective? I see no other explanation why it would deem the call 'foo(NULL)' ambiguous. V -- I do not respond to top-posted replies, please don't ask |
Luca Risolia <luca.risolia@linux-projects.org>: May 26 10:45PM +0200 Il 26/05/2015 21:50, Victor Bazarov ha scritto: > > implementation because the overload is really ambiguous. > Doesn't what you've just written mean that the your C++ implementation > is defective? No (see below). > I see no other explanation why it would deem the call > 'foo(NULL)' ambiguous. One conforming C++11 implementation is allowed define NULL as: #define NULL 0L in which case foo(NULL) is ambiguous if you only have the foo(int) and foo(int*) overloads defined, because conversion from long to int and 0L to int* are considered equally good. |
Glen Stark <mail@glenstark.net>: May 26 07:30PM Hi Everyone. Consider the following: class A; // some non trivial class. class B; // another non trivial class. template<typename T> class Foo { public: // some public stuff usint T. private: const int m_code; // integer needed for legacy stuff. // some private stuff which uses T. } I would like to do something like: Foo<A> f; -> instantiating Foo<A> results in m_code == 5 Foo<B> g; -> instantiating Foo<B> reusults in m_code == 10 In fact, then the m_code could be a constexpr, which might open up further refactorings. I figure if I experiment and read around I'll be able to come up with a solution, but I'm doubtful I'll come up with the most elegant solution, and I figure one of you could maybe tell me what that is? Thanks for your help, hope my question was clearly phrased. Glen |
Ian Collins <ian-news@hotmail.com>: May 27 07:52AM +1200 Glen Stark wrote: > Foo<B> g; -> instantiating Foo<B> reusults in m_code == 10 > In fact, then the m_code could be a constexpr, which might open up > further refactorings. You could make m_code a static member and specialise: template<> const int Foo<A>::m_code = 5; template<> const int Foo<B>::m_code = 10; -- Ian Collins |
Victor Bazarov <v.bazarov@comcast.invalid>: May 26 03:57PM -0400 On 5/26/2015 3:43 PM, Stefan Ram wrote: > Glen Stark <mail@glenstark.net> writes: >> I would like to do something like: > I am not an expert for this topic, here is a wild guess: Truly wild... > template<> struct C< A >: common< A >{ const int c = 5; }; > template<> struct C< B >: common< B >{ const int c = 10; }; > int main(){ ::std::cout << C< A >{}.c << '\n'; } There is no need to use inheritance, IMHO. You need some kind of type traits stuff, specialized for A and B, and use it in Foo: class A; // some non trivial class. class B; // another non trivial class. template<typename T> struct traits_used_by_Foo { }; template<> struct traits_used_by_Foo<A> { enum { code = 5 }; }; template<> struct traits_used_by_Foo<B> { enum { code = 10 }; }; template<typename T> class Foo { public: // some public stuff usint T. private: const int m_code = traits_used_by_Foo<T>::code; // some private stuff which uses T. }; V -- I do not respond to top-posted replies, please don't ask |
bleachbot <bleachbot@httrack.com>: May 26 02:33PM +0200 |
ram@zedat.fu-berlin.de (Stefan Ram): May 26 07:43PM >I would like to do something like: I am not an expert for this topic, here is a wild guess: #include <iostream> #include <ostream> class A; class B; template< typename T >struct common {}; template< typename T >struct C : common< T >{ const int m_code; }; template<> struct C< A >: common< A >{ const int c = 5; }; template<> struct C< B >: common< B >{ const int c = 10; }; int main(){ ::std::cout << C< A >{}.c << '\n'; } . |
Doug Mika <dougmmika@gmail.com>: May 26 09:37AM -0700 By definition: A function object that combines two function objects is called an adaptive function object. Can anyone provide me with an example of an adaptive function object or a link to an example? Or is it simply that there are two operator() functions in a class that is an adaptive function object? |
Victor Bazarov <v.bazarov@comcast.invalid>: May 26 01:04PM -0400 On 5/26/2015 12:37 PM, Doug Mika wrote: > example of an adaptive function object or a link to an example? Or > is it simply that there are two operator() functions in a class that > is an adaptive function object? Here it is: http://lmgtfy.com/?q=%22adaptive+function+object%22+C%2B%2B V -- I do not respond to top-posted replies, please don't ask |
legalize+jeeves@mail.xmission.com (Richard): May 26 05:11PM [Please do not mail me a copy of your followup] Doug Mika <dougmmika@gmail.com> spake the secret code >By definition: A function object that combines two function objects is >called an adaptive function object. Can anyone provide me with an >example of an adaptive function object or a link to an example? #include <algorithm> #include <functional> #include <iostream> #include <iterator> #include <vector> template < typename T, typename Less = std::less<T>, typename More = std::greater<T> class range_comparison { public: range_comparison(T min_bound, T max_bound) : m_min_bound(min_bound), m_max_bound(max_bound) { } bool operator()(T val) { return !lesser(val, m_min_bound) && !greater(val, m_max_bound); } private: Less lesser; More greater; T m_min_bound; T m_max_bound; }; int main() { std::vector<int> vals{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; std::copy_if(std::begin(vals), std::end(vals), std::ostream_iterator<int>(std::cout, "\n"), range_comparison<int>(3, 6)); } gives 3 4 5 6 -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
"BASTA CENSUR-A-SSASSINA RENZUSCONICCHIA!" <jerrytodolon@gmx.com>: May 26 04:24AM -0700 CIVIL HERO AND STOCKS, COMMODITIES, CURRENCIES GENIUS MICHELE NISTA MICHELENISTA@GMX.COM! HE GET IT RIGHT ON WORLDWIDE SECURITIES, DE FACTO, ALWAYS! BOUT 6000 PREDICTIONS ON INTERNET SINCE 9.2007: 6000 SUCCESS! 100% SHOCKING WINNING SCORE! "PODEMOS"! GENIUS, KING MIDAS, CIVIL HERO MICHELE NISTA MICHELENISTA@GMX.COM! HE GET IT RIGHT ON WORLDWIDE STOCKS, CURRENCIES & COMMODITIES ALWAYS! ABOUT 6000 PREDICTIONS ON INTERNET SINCE 9.2007: 6000 SUCCESS! 100% SHOCKING WINNING SCORE!!! GENIUS, KING MIDAS, CIVIL HERO MICHELE NISTA (MICHELENISTA@GMX.COM) ADVANCED IN EXTREMELY PERFECT WAY THE CONTINUOUS WALL STREET CRASH OF 1987 ( AND HE WAS, MORE OR LESS, JUST 20, AT THE TIME)! AS THE ONE OF 2007, 2008 AND BEGINNING OF 2009 WITH "JUST" 1 AND HALF YEAR OF INCREDIBLY WINNING FORETASTE! GENIUS, KING MIDAS, CIVIL HERO MICHELE NISTA MICHELENISTA@GMX.COM AVDANCED IN EXTREMELY PERFECT WAY, THEN, THE MORE OF DOUBLING OF WALL STREET, SINCE 3.2009! HE PROPHESIED ALL THIS ON INTERNET, AGAIN, WITH MONTHS AND MONTHS IN ADVANCE! ALL AT FANTASTIC LIGHT OF SUNSHINE!!! ALL PROVABLE AND VISIBLE STILL NOW!!! GENIUS, KING MIDAS, CIVIL HERO MICHELE NISTA (MICHELENISTA@GMX.COM) WAS "ONE OF THE NUMBER ONES" OF ITALIAN STOCK EXCHANGE, IN THE 90S, PRODUCING OVER 10 MILIONS OF EUROS OF COMMISSIONS OF THE 90S ( SO, 15 MILIONS OF NOW), FROM BELOW ZERO: WAS THE ABSOLUTE IDOL OF GOLDMAN SACHS, MERRILL LYNCH, AND NEARLY ANY "FOR GOOD" INVESTMENT BANK IN THE WORLD! THAT'S WHY EVERYONE WAS GIVING HIM AND STILL GIVE HIM THE NICK OF KING MIDAS! INGENIOUS HERO MICHELE NISTA HAS A GREAT HEART TOO, "NOT JUST" A SORT OF INVINCIBLE INTUITION! HE DEDICATES, SINCE HE WAS 17, ALL HIS GIFTS OF HEAVEN HE HAS TO POOREST PEOPLE IN THE WORLD, VOLUNTEERING AND NOT ONLY, FOR MANY ORGANIZATIONS SAVING OR IMPROVING SUFFERING LIVES IN LATIN AMERICA AND AFRICA. HE IS CERTAINLY A CIVIL INCORRUPTIBLE HERO TOO! IN THE LAST 21 YEARS, IN MILAN, WAS THE MOST TENACIOUS MAN HUNTING TO DESTROY THE ASSASSIN DICTATORSHIP OF MAFIOSO, MEGA MAFIA MONEY LAUNDERER, EXTREME NAZIFASCIST, LIAR, MEGA THIEF, CORRUPTING PIG, PRINCIPAL OF HUNDREDS OF MURDERS AND SLAUGHTERS, VERY ASCERTAINED PEDOPHILE SILVIO BERLUSCONI! FOR ALL THIS, THERE WERE FOUR ATTEMPTS OF KILLING HIM, ORDERED BY BASTARD SANGUINARY, AS WELL AS METASTASES OF THE ENTIRE WORLD: SILVIO BERLUSCONI!!!! AND HIS FATHER LOST LIFE ON ORDER OF NAZIFASCIST AND COSA NOSTRA'S BRUTAL, VICIOUS, CRUEL, FEROCIOUS PRINCIPAL OF KILLING SILVIO BERLUSCONI (MAKING SHREWDLY TO PASS, VIA HIS PRIVATE OR PUBLIC NEW "OVRA, GESTAPO AND DINA" AL HIS ABSOLUTE REPELLENT HINDREDS OF HOMICIDES FOR FALSE ACCIDENTS, FALSE SUICIDES, FALSE ILLNESS, ALL THE TIMES)! AS A MATTER OF FACT, GENIUS, KING MIDAS, DEMOCRAT HERO MICHELE NISTA MICHELENISTA@GMX.COM" DECIDED TO EMIGRATE" TO LONDON, ON 2003, TO REMAIN ALIVE!! BUT GOD, IF HE'LL CONTINUE TO DESERVE SO, WILL MAKE HIM WIN!!! GROUP OF FRIENDS AND CLIENTS, EXTREMELY GRATEFUL TO THIS KING MIDAS, TO THIS INGENIOUS AND CIVIL HERO OF OUR TIMES: MICHELE NISTA (MICHELENISTA@GMX.COM)!!! |
fl <rxjwg98@gmail.com>: May 25 05:10PM -0700 Hi, I get a piece of code which is useful for my project. The code is incomplete. Thus, I want to modify it to work for me. The problem is from a matrix usage. It has the following snippet: matrix state(6,1); /*initializes the state*/ state[0][0]=0.1; The matrix is known as two dimension, which looks just like a two dimension array. Is it a pseudo code on the state variable? If it is the real code, I don't know how to define the class to make it like a two dimensional array. Could you help me on the problem? Thanks, |
Ian Collins <ian-news@hotmail.com>: May 26 12:18PM +1200 fl wrote: > The matrix is known as two dimension, which looks just like a two dimension > array. Is it a pseudo code on the state variable? If it is the real code, > I don't know how to define the class to make it like a two dimensional array. constexpr size_t X = some size; constexpr size_t Y = some size; using Matrix = std::array<std::array<double,Y>,X>; Matrix matrix; -- Ian Collins |
fl <rxjwg98@gmail.com>: May 25 07:17PM -0700 On Monday, May 25, 2015 at 5:18:44 PM UTC-7, Ian Collins wrote: > Matrix matrix; > -- > Ian Collins Thank Ian. Your reply is really helpful to me. I am still new to C++. Could you make it a real specific example of your pseudo code? I have tried some time, but it does not work yet. For example, what constexpr would be? size_t is a type? |
fl <rxjwg98@gmail.com>: May 25 07:24PM -0700 On Monday, May 25, 2015 at 5:18:44 PM UTC-7, Ian Collins wrote: > Matrix matrix; > -- > Ian Collins I have tried this: Matrix = std::array<std::array<double,6>,6>; missing type specifier - int assumed. 'array' : is not a member of 'std' 'array' : undeclared identifier type 'double' unexpected The above message is from MSVC compiler. Could you help me through the build? Thanks |
Ian Collins <ian-news@hotmail.com>: May 26 04:16PM +1200 fl wrote: > Could you make it a real specific example of your pseudo code? I have tried > some time, but it does not work yet. For example, what constexpr would be? > size_t is a type? It wasn't pseudo code! Your C++ book should explain constexpr and size_t. Let's try again with a complete example: #include <array> constexpr size_t X = 10; constexpr size_t Y = 10; using Matrix = std::array<std::array<double,Y>,X>; int main() { Matrix state; state[0][0] = 0.1; } -- Ian Collins |
Ian Collins <ian-news@hotmail.com>: May 26 04:17PM +1200 fl wrote: >> Ian Collins > I have tried this: > Matrix = std::array<std::array<double,6>,6>; Why did you omit the "using"? It wasn't prose, it's a C++ keyword! -- Ian Collins |
fl <rxjwg98@gmail.com>: May 25 11:28PM -0700 On Monday, May 25, 2015 at 9:18:08 PM UTC-7, Ian Collins wrote: > Why did you omit the "using"? It wasn't prose, it's a C++ keyword! > -- > Ian Collins Excuse me. I did use using at first, but it still can't pass build with MSVC. Now, it is found that MSVC does not support c++11. Whether below line is equivalent to typedef in MSVC 2010? using Matrix = std::array<std::array<double,Y>,X>; Now I find that a two-dimensional array is similar to a Matrix in the project. My new question is whether a two-dimensional array can be redefined as a Matrix in order to support matrix multiplication in the following (A, P, Q are nXn Matrix, ' is transpose operation)? p = A * P * A' + Q; Thanks again. |
Paavo Helde <myfirstname@osa.pri.ee>: May 26 02:20AM -0500 fl <rxjwg98@gmail.com> wrote in > Excuse me. I did use using at first, but it still can't pass build > with MSVC. Now, it is found that MSVC does not support c++11. > Whether below line is equivalent to typedef in MSVC 2010? So why don't you upgrade to a newer version of MSVC, there has been at least 3 releases after MVSC 2010 and the C++11 standard is 4 years old. Nobody in public forums is interested in providing outdated and inferior solutions. Cheers Paavo |
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: May 26 10:50AM +0100 On Mon, 25 May 2015 23:28:45 -0700 (PDT) > redefined as a Matrix in order to support matrix multiplication in > the following (A, P, Q are nXn Matrix, ' is transpose operation)? > p = A * P * A' + Q; With C++98/03, you can define an alias for a matrix type using the built-in array syntax: const size_t X = 6; const size_t Y = 4; typedef double Matrix[Y][X]; // Matrix is now a type alias for a // statically sized 4×6 matrix of doubles Using this approach you will need to write vector and matrix multiplication functions yourself, which take and return such matrices. They can accordingly be tedious to use. A more advanced approach is to write a Matrix class, with multiplication and addition as overloaded operators for the class. In such a class, for a dynamically sized matrix you probably would not use a multi-dimensional matrix internally, but instead use pointer arithmetic on a single dimensional array to arrive at the correct cell. This is because matrix[2][3] is equivalent to arr[ncols * 2 + 3], where ncols is the number of columns (the X value above). Read also: https://isocpp.org/wiki/faq/freestore-mgmt#multidim-arrays https://isocpp.org/wiki/faq/freestore-mgmt#multidim-arrays2 and the immediately following FAQs. Matrices are tricky in C++, with a number of different approaches which involve different trade-offs for static and dynamic sizing and exception safety, which is why they are often part of a homework assignment :) Chris |
"Öö Tiib" <ootiib@hot.ee>: May 26 03:46AM -0700 On Tuesday, 26 May 2015 09:29:05 UTC+3, fl wrote: > > Why did you omit the "using"? It wasn't prose, it's a C++ keyword! > Excuse me. I did use using at first, but it still can't pass build > with MSVC. Now, it is found that MSVC does not support c++11. 'std::array' is a simple template mostly copied from 'boost::array' and it was certainly present in C++ library of MSVC 2010. > Whether below line is equivalent to typedef in MSVC 2010? > using Matrix = std::array<std::array<double,Y>,X>; Yes. It is just easier to read than: typedef std::array<std::array<double,Y>,X> Matrix; Why you start a new project with 3 generations old compiler? > Now I find that a two-dimensional array is similar to a Matrix in the > project. What you mean by a two-dimensional array? You mean raw array? It is rather tricky to work with raw arrays in C++ since those decay to pointer of first element on slightest provocation (that means almost always when you try to use one for anything). It is therefore advisable to encapsulate raw array to a class to make it bit more manageable (and that is what std::array does). > redefined as a Matrix in order to support matrix multiplication in the > following (A, P, Q are nXn Matrix, ' is transpose operation)? > p = A * P * A' + Q; No. There are no such thing as post-fix operator ' in C++ and there are no such thing as matrix operations in C++ and also you can't make operators (or functions) that return raw arrays in C++. Raw arrays can't be passed or returned by value (as legacy from C). You should read a good beginner level book about C++; you won't get anywhere by asking these novice level questions in forums. When we need to do linear algebra with matrices in C++ then we usually use something outside of standard C++ for example some linear algebra library (Armadillo, Eigen or Boost.UBLAS). These already contain classes for representing matrices so you should not invent your own types of matrices but simply use theirs. |
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