Sign in to follow this  

Unity Obtaining the type of elements within a vector of vectors.

This topic is 2317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[size="2"][color="black"][font="Arial"][size="2"]Lately, I've been making use of std::vector's'value_type' typedefs in function parameters, so that code written thus;

[code]
template<typename TypeA, typename TypeB>
void Foo
(
const TypeA & A,
const TypeB & B
)
{
}
[/code]

can be rewritten as;

[code]
template<typename Type>
void Foo
(
const Type & A,
typename Type::value_type b
)
{
}
[/code]

for types that deploy the 'value_type' typedef. However, when it comes onto types that are vectors of vectors then code like this;

[code]
template<typename Type>
void Foo
(
const Type & A,
typename Type::value_type::size_type b
)
{
}
[/code]

compiles without any issues, where as the following code;

[code]
template<typename Type>
void Foo
(
const Type & A,
typename Type::value_type::value_type b
)
{
}
[/code]

does not. When nesting value_type like this, my MSV C++ 2010 Express compiler comes up with:

error C2893: Failed to specialize function template 'void Foo(const Type&,Type::value_type::{ctor})

There are obvious work arounds regarding this problem (like simply using another type parameter in the template), but I would just like to know why one type of nesting works and not the other.

And besides... Template programming is a bit of a chink in my C++ armour at the moment, so any opportunity to gain a heads up would be much appreciated![/size][/font][/color]

[/size]

Share this post


Link to post
Share on other sites
I don't know why it doesn't work for you. This code works for me
[code]#include <vector>

template<typename Type>
void Foo
(
const Type & A,
typename Type::value_type::value_type b
)
{
}

int main()
{
std::vector<std::vector<int> > v;
Foo(v, 4);
}[/code]

Share this post


Link to post
Share on other sites
I also checked and it works with gcc 4.4.3 and intel 12.0.2.
[code]
#include <iostream>
#include <vector>

template<class V>
void foo(const V &v, typename V::value_type::value_type b)
{
std::cout << b << std::endl;
}

int main(int argc, char *arvg[])
{

std::vector<std::vector<int> > vec;
foo(vec, 45);

return 0;
}
[/code]


Does this work? (just guessing)
[code]
template <class T>
struct funky_workaround { typedef typename T::value_type value_type; };

template<class V>
void foo(const V &v, typename funky_workaround<typename V::value_type>::value_type b)
{
std::cout << b << std::endl;
}
[/code]

Share this post


Link to post
Share on other sites
Yeah... Checked and rechecked my code again. Still no joy!

I even used your version Wooh just to make sure... And it still won't compile...

But thanks japro! That funky work around of yours did do the trick... But it sure is... errr... funky LOL!

In any case, the fact that my "bugged" code compiles for some of you indicates that something might not be right with my compiler (that or it needs upgrading).

Anyway, thanks for replies ;-)

BTW Wooh... Just out of curiosity, what compiler are you using?

Share this post


Link to post
Share on other sites
[quote name='CodeStorm' timestamp='1313107340' post='4848014']BTW Wooh... Just out of curiosity, what compiler are you using?[/quote]
gcc 4.2.4

Share this post


Link to post
Share on other sites
[quote name='Wooh' timestamp='1313108512' post='4848018']
[quote name='CodeStorm' timestamp='1313107340' post='4848014']BTW Wooh... Just out of curiosity, what compiler are you using?[/quote]
gcc 4.2.4
[/quote]


LOL! Thanks... Yeah that figures I guess...

Just been checking out MS Connect which apparently has a few people with issues regarding [font=Verdana][size=2][b]C2893[/b][/size][/font].

So it seems MSV C++ Express 2010 still has a few bugs in it.

Share this post


Link to post
Share on other sites

This topic is 2317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628710
    • Total Posts
      2984338
  • Similar Content

    • By AndySv
        Total Music Collection (http://u3d.as/Pxo)   THE COLLECTION CONTAINS:   Mega Game Music Collection   Universal Music Collection   Huge library of high quality music for any project! All at an incredibly low price!   - 2,5GB of high quality audio - 100+ different music tracks - Loop and short versions   Action, fantasy, casual, horror, puzzle, epic, dramatic, romantic, positive, inspiring, motivational and more!
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064

      View full story
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064
    • By Dafu
      Hello all,
      I've been hard at work on a new retro pixel-perfect framework called FES Retro Game Framework. It is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      My own game I started working on using FES, a roguelike, very early: https://simmer.io/@Dafu/merl
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064
       
       
    • By Apollo Cabrera
      Yasss!!! My first Unity3d game is on the App Store and Google Play.
      Download please! About 30 minutes to get through 5 missions.
      Let me know what you guys think.
      Thanks a bunch
       
  • Popular Now