- Extracting type from a vector instance - 2 Updates
- Aliases - 4 Updates
- RWCollectable Replacement - 5 Updates
- Determining endianess at compile time - 2 Updates
- a template clads static element - 2 Updates
Doug Mika <dougmmika@gmail.com>: May 20 01:36PM -0700 Why would the following not work? int main(){ vector<double> vd; decltype(vd.value_type) otherDouble = 2.2; } Thanks. |
Paavo Helde <myfirstname@osa.pri.ee>: May 20 03:57PM -0500 Doug Mika <dougmmika@gmail.com> wrote in news:6f7085a7-cf81-4ec3-a2b6- > decltype(vd.value_type) otherDouble = 2.2; > } > Thanks. value_type is already a type, so applying decltype on it does not make sense. I guess this is what you are after: #include <vector> int main(){ std::vector<double> vd; decltype(vd)::value_type otherDouble = 2.2; } hth Paavo |
Doug Mika <dougmmika@gmail.com>: May 20 12:02PM -0700 Hi, could someone describe in detail (line for line) what the following code does: I found it in a book, and it's not explained clearly, if at all. (In particular, I don't understand "typename C::value_type" using the scope resolution operator on a template parameter. and should it be "Container<Element_type>" instead? Also, I should mention that Vector is a custom vector class created by the author.) template<typename C> using Element_type = typename C::value_type; template<typename Container> void algo(Container& c) { Vector<Element_type<Container>> vec; //keep results here //... } where Vector is: template<typename T> class Vector { public: using value_type = T; // ... }; Thanks to all and I know I didn't include the code for the custom Vector class, but I hope the above will suffice to give someone an idea. |
Wouter van Ooijen <wouter@voti.nl>: May 20 09:09PM +0200 Doug Mika schreef op 20-May-15 om 9:02 PM: > . . . > template<typename C> > using Element_type = typename C::value_type; The scope resolution is used because the author wants to use something that is declared within the class C. Not a per-object thing like a normal method or an attribute, but something per-class, like a static method or a nested classd. Hence :: instead of . Now the compiler knows that C::value_type is something within the class C, but it does not know what it is (a class? a method? ...). Hence the typename prefix to tell the compiler that is is a class. Wouter |
Victor Bazarov <v.bazarov@comcast.invalid>: May 20 03:17PM -0400 On 5/20/2015 3:02 PM, Doug Mika wrote: > Vector is a custom vector class created by the author.) > template<typename C> > using Element_type = typename C::value_type; This declares 'Element_type' as a template-id (similar to 'typedef-id' that you could declare using "typedef") that can be used with a single argument, as if you could any other template, except that the compiler should immediately upon encountering it look it up and instead use as a typename the template argument's member 'value_type'. Example: if you in your code use 'Element_type<Blah>', the compiler should find the member of 'Blah' called "value_type" and use that instead. struct Foo { typedef int value_type; // here is the member }; int main() { Element_type<Foo> i; // declares 'i' as 'int' } > template<typename Container> > void algo(Container& c) { > Vector<Element_type<Container>> vec; //keep results here Here the compiler should look up the member "value_type" in whatever the actual type 'Container' is, and substitute it to make the line read Vector<that> vec; where "that" is supposed to be the type declared as a member of 'Container' (whatever that is for this specific instantiation of the 'algo' template) under the name 'value_type'. > Thanks to all and I know I didn't include the code for the custom > Vector class, but I hope the above will suffice to give someone an > idea. If you want to learn more about the resulting types, you should start using 'typeid' operator in your test code: std::cout << "Type of 'whatIwant2know' is " << typeid(whatIwant2know).name() << std::endl; Don't forget to include <typeinfo> header. V -- I do not respond to top-posted replies, please don't ask |
Doug Mika <dougmmika@gmail.com>: May 20 12:54PM -0700 On Wednesday, May 20, 2015 at 2:02:56 PM UTC-5, Doug Mika wrote: > // ... > }; > Thanks to all and I know I didn't include the code for the custom Vector class, but I hope the above will suffice to give someone an idea. Ok, I think that was fairly clear and well explained, thanks, but I had a quick question. Could I use a particular instance instead of type? ie vector<int> vi(1)={1}; Element_type<vi> i; //would this be identical to int i;? or how about this: Element_type<vector<int>> i;//int i; ? |
shirishB <shirishbhalekar1@gmail.com>: May 20 02:24AM -0500 Is there is any Reply. |
Paavo Helde <myfirstname@osa.pri.ee>: May 20 08:55AM -0500 shirishB <shirishbhalekar1@gmail.com> wrote in > Is there is any Reply. Reply to what? |
"Öö Tiib" <ootiib@hot.ee>: May 20 07:30AM -0700 On Wednesday, 20 May 2015 16:55:57 UTC+3, Paavo Helde wrote: > news:MPadndSmw4Ywq8HInZ2dnUU7-IWdnZ2d@giganews.com: > > Is there is any Reply. > Reply to what? It was response to a post from 2006. It asked "open solution" replacement to some random intrusive base class "RWCollectable" from some random legacy library. It perhaps let the library to do some sort of serialization. |
red floyd <no.spam@its.invalid>: May 20 09:40AM -0700 On 5/20/2015 7:30 AM, Öö Tiib wrote: > replacement to some random intrusive base class "RWCollectable" > from some random legacy library. It perhaps let the library > to do some sort of serialization. I'm guessing it was a Rogue Wave library. |
Jorgen Grahn <grahn+nntp@snipabacken.se>: May 20 06:07PM On Wed, 2015-05-20, red floyd wrote: > On 5/20/2015 7:30 AM, 嘱 Tiib wrote: ... >> from some random legacy library. It perhaps let the library >> to do some sort of serialization. > I'm guessing it was a Rogue Wave library. Wow, thanks. I had forgotten all about Rogue Wave -- it was before my time. Feels good to, for once, have missed something because you're too young ... What's its legacy, by the way? I'm guessing it was radically different in scope and philosophy compared to the STL. Are any of the ideas alive today? /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Juha Nieminen <nospam@thanks.invalid>: May 20 07:22AM > I think I prefer the CMake way: simply execute a program at build time > that gives you the answer and use this to generate a header with the > necessary symbol defined. I think a well-designed library ought to avoid requiring external compiling tools if possible. If I can make a library as "plug&play" as possible, I very much prefer that. --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
scott@slp53.sl.home (Scott Lurndal): May 20 02:09PM >When cross compiling you describe the target system with a toolchain >file and the methods described on the wiki. ><http://www.vtk.org/Wiki/CMake_Cross_Compiling> In other words, no, that won't work when cross compliing for different architectures. As someone who has been developing operating systems[*] on big, little and bi-endian systems since 1979, I'm quite comfortable with using the implementation header files (included as part of the tool chain) to determine the endianness on unix, unix-like and linux systems. That's why I'm also comfortable using dual leading underscores for defines, because when I do, it _is_ part of the implementation. Granted, I should have edited the example I posted earlier to avoid encouraging misuse by readers writing application level code. [*] including the compilation tools (e.g. pcc), associated header files standard libraries etc. |
asetofsymbols@gmail.com: May 19 11:35PM -0700 Yes but if i have template<class T> class per{ // .... per(){++v; /*...*/ } static int v; }; int per<int>::v=0; I can access v from function g below void g(void) {... per<int>::v=1; } If instead one has template<class T> int per<T>::v=0; How g would access v? |
Wouter van Ooijen <wouter@voti.nl>: May 20 08:43AM +0200 > If instead one has > template<class T> int per<T>::v=0; > How g would access v? 'how' is a strange question in this context. It does. The line template<class T> int per<T>::v=0; Defines a v for each instantiation of per, hence when you use per<int> the compiler will define per<int>::v. Wouter |
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