Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Derek Gaston <friedmud@gm...> - 2008-12-17 05:51:49
|
Unfortunately we also have vectors of vectors (of vectors)! But yeah I think we should either do that or take print capability out of parameters. I'll do something tomorrow. Sent from my iPhone On Dec 16, 2008, at 8:17 PM, Benjamin Kirk <benjamin.kirk@...> wrote: >> os << _value; >> >> This doesn't work if the parameter type is something like a >> std::vector... it won't even compile. Any ideas on dealing with >> this? For now, we've just commented out that line of code (we don't >> need to print the parameters) and continued on.... but what is the >> correct solution? > > Hmm... Create a generic <typename T> (as is currently done), and > also add a > <std::vector<typename T> > specialization: > > template <typename T> > inline > void Parameters::Parameter<T>::print (std::ostream& os) const > { > os << _value; > } > > template <std::vector< typename T> > > inline > void Parameters::Parameter<T>::print (std::ostream& os) const > { > for (unsinged int p=0; ...) > } > > Will that do it? > > -Ben > > |
From: Derek Gaston <friedmud@gm...> - 2008-12-17 00:49:23
|
On line 255 of parameters.h we have: os << _value; This doesn't work if the parameter type is something like a std::vector... it won't even compile. Any ideas on dealing with this? For now, we've just commented out that line of code (we don't need to print the parameters) and continued on.... but what is the correct solution? Derek |
From: Benjamin Kirk <benjamin.kirk@na...> - 2008-12-17 03:17:45
|
> os << _value; > > This doesn't work if the parameter type is something like a > std::vector... it won't even compile. Any ideas on dealing with > this? For now, we've just commented out that line of code (we don't > need to print the parameters) and continued on.... but what is the > correct solution? Hmm... Create a generic <typename T> (as is currently done), and also add a <std::vector<typename T> > specialization: template <typename T> inline void Parameters::Parameter<T>::print (std::ostream& os) const { os << _value; } template <std::vector< typename T> > inline void Parameters::Parameter<T>::print (std::ostream& os) const { for (unsinged int p=0; ...) } Will that do it? -Ben |
From: Derek Gaston <friedmud@gm...> - 2008-12-17 05:51:49
|
Unfortunately we also have vectors of vectors (of vectors)! But yeah I think we should either do that or take print capability out of parameters. I'll do something tomorrow. Sent from my iPhone On Dec 16, 2008, at 8:17 PM, Benjamin Kirk <benjamin.kirk@...> wrote: >> os << _value; >> >> This doesn't work if the parameter type is something like a >> std::vector... it won't even compile. Any ideas on dealing with >> this? For now, we've just commented out that line of code (we don't >> need to print the parameters) and continued on.... but what is the >> correct solution? > > Hmm... Create a generic <typename T> (as is currently done), and > also add a > <std::vector<typename T> > specialization: > > template <typename T> > inline > void Parameters::Parameter<T>::print (std::ostream& os) const > { > os << _value; > } > > template <std::vector< typename T> > > inline > void Parameters::Parameter<T>::print (std::ostream& os) const > { > for (unsinged int p=0; ...) > } > > Will that do it? > > -Ben > > |
From: Derek Gaston <friedmud@gm...> - 2008-12-22 20:39:58
Attachments:
Message as HTML
|
Ok - I give up... someone tell me what the hell I'm doing wrong. I'm trying to add the following function to parameters.h (right underneath the generic version): template <typename T> inline void Parameters::Parameter<std::vector<T> >::print (std::ostream& os) const { for (unsigned int i=0; i<_value.size(); i++) os << _value[i] << " "; } And I get errors: invalid use of undefined type 'class Parameters::Parameter<std::vector<T, std::allocator<_CharT> > >' /Users/gastdr/projects/libmesh/include/utils/parameters.h:163: error: declaration of 'class Parameters::Parameter<std::vector<T, std::allocator<_CharT> > >' /Users/gastdr/projects/libmesh/include/utils/parameters.h:260: error: template definition of non-template 'void Parameters::Parameter<std::vector<T, std::allocator<_CharT> > >::print(std::ostream&) const' /Users/gastdr/projects/libmesh/include/utils/parameters.h: In member function 'void Parameters::Parameter<std::vector<T, std::allocator<_CharT> > >::print(std::ostream&) const': But... if I do: template <> inline void Parameters::Parameter<std::vector<Real> >::print (std::ostream& os) const { for (unsigned int i=0; i<_value.size(); i++) os << _value[i] << " "; } Like normal template specialization.... it works fine. I've tried looking this up in various places.... and from what I can see I'm doing it correctly.... so it's time for some outside advice. I've also tried hundreds of permutations.... and just can't get the damn thing to go. Thanks! Derek On Tue, Dec 16, 2008 at 8:17 PM, Benjamin Kirk <benjamin.kirk@...>wrote: > > os << _value; > > > > This doesn't work if the parameter type is something like a > > std::vector... it won't even compile. Any ideas on dealing with > > this? For now, we've just commented out that line of code (we don't > > need to print the parameters) and continued on.... but what is the > > correct solution? > > Hmm... Create a generic <typename T> (as is currently done), and also add a > <std::vector<typename T> > specialization: > > template <typename T> > inline > void Parameters::Parameter<T>::print (std::ostream& os) const > { > os << _value; > } > > template <std::vector< typename T> > > inline > void Parameters::Parameter<T>::print (std::ostream& os) const > { > for (unsinged int p=0; ...) > } > > Will that do it? > > -Ben > > > |
From: Derek Gaston <friedmud@gm...> - 2008-12-22 20:53:25
Attachments:
Message as HTML
|
At this point I'm actually thinking about inheriting from Parameter and overriding the virtual print() function with an empty function.... that would take care of the problem without having to modify libMesh... What do you guys think? Derek On Mon, Dec 22, 2008 at 1:38 PM, Derek Gaston <friedmud@...> wrote: > Ok - I give up... someone tell me what the hell I'm doing wrong. I'm > trying to add the following function to parameters.h (right underneath the > generic version): > template <typename T> > inline > void Parameters::Parameter<std::vector<T> >::print (std::ostream& os) const > { > for (unsigned int i=0; i<_value.size(); i++) > os << _value[i] << " "; > } > > And I get errors: > > invalid use of undefined type 'class Parameters::Parameter<std::vector<T, > std::allocator<_CharT> > >' > /Users/gastdr/projects/libmesh/include/utils/parameters.h:163: error: > declaration of 'class Parameters::Parameter<std::vector<T, > std::allocator<_CharT> > >' > /Users/gastdr/projects/libmesh/include/utils/parameters.h:260: error: > template definition of non-template 'void > Parameters::Parameter<std::vector<T, std::allocator<_CharT> > > >::print(std::ostream&) const' > /Users/gastdr/projects/libmesh/include/utils/parameters.h: In member > function 'void Parameters::Parameter<std::vector<T, std::allocator<_CharT> > > >::print(std::ostream&) const': > > > But... if I do: > > template <> > inline > void Parameters::Parameter<std::vector<Real> >::print (std::ostream& os) > const > { > for (unsigned int i=0; i<_value.size(); i++) > os << _value[i] << " "; > } > > Like normal template specialization.... it works fine. I've tried looking > this up in various places.... and from what I can see I'm doing it > correctly.... so it's time for some outside advice. I've also tried > hundreds of permutations.... and just can't get the damn thing to go. > > Thanks! > Derek > > > On Tue, Dec 16, 2008 at 8:17 PM, Benjamin Kirk <benjamin.kirk@...>wrote: > >> > os << _value; >> > >> > This doesn't work if the parameter type is something like a >> > std::vector... it won't even compile. Any ideas on dealing with >> > this? For now, we've just commented out that line of code (we don't >> > need to print the parameters) and continued on.... but what is the >> > correct solution? >> >> Hmm... Create a generic <typename T> (as is currently done), and also add >> a >> <std::vector<typename T> > specialization: >> >> template <typename T> >> inline >> void Parameters::Parameter<T>::print (std::ostream& os) const >> { >> os << _value; >> } >> >> template <std::vector< typename T> > >> inline >> void Parameters::Parameter<T>::print (std::ostream& os) const >> { >> for (unsinged int p=0; ...) >> } >> >> Will that do it? >> >> -Ben >> >> >> > |
From: John Peterson <peterson@cf...> - 2008-12-22 22:50:57
|
Hey, Not sure if this is it but could you try: void Parameters::Parameter<typename std::vector<T> >::print (std::ostream& os) const (just add the typename qualifier, everything else the same.) Anyway, that is what I always try when I'm dealing with templates and there is a type which depends on T... -- John On Mon, Dec 22, 2008 at 2:38 PM, Derek Gaston <friedmud@...> wrote: > Ok - I give up... someone tell me what the hell I'm doing wrong. I'm trying > to add the following function to parameters.h (right underneath the generic > version): > template <typename T> > inline > void Parameters::Parameter<std::vector<T> >::print (std::ostream& os) const > { > for (unsigned int i=0; i<_value.size(); i++) > os << _value[i] << " "; > } > And I get errors: > invalid use of undefined type 'class Parameters::Parameter<std::vector<T, > std::allocator<_CharT> > >' > /Users/gastdr/projects/libmesh/include/utils/parameters.h:163: error: > declaration of 'class Parameters::Parameter<std::vector<T, > std::allocator<_CharT> > >' > /Users/gastdr/projects/libmesh/include/utils/parameters.h:260: error: > template definition of non-template 'void > Parameters::Parameter<std::vector<T, std::allocator<_CharT> > >>::print(std::ostream&) const' > /Users/gastdr/projects/libmesh/include/utils/parameters.h: In member > function 'void Parameters::Parameter<std::vector<T, std::allocator<_CharT> > >>::print(std::ostream&) const': > > But... if I do: > template <> > inline > void Parameters::Parameter<std::vector<Real> >::print (std::ostream& os) > const > { > for (unsigned int i=0; i<_value.size(); i++) > os << _value[i] << " "; > } > Like normal template specialization.... it works fine. I've tried looking > this up in various places.... and from what I can see I'm doing it > correctly.... so it's time for some outside advice. I've also tried > hundreds of permutations.... and just can't get the damn thing to go. > Thanks! |
From: Derek Gaston <friedmud@gm...> - 2008-12-22 23:40:01
Attachments:
Message as HTML
|
I've done similar things in the past... but that isn't working in this case. In particular I get: error: using 'typename' outside of template error: 'T' was not declared in this scope Sigh. Derek On Mon, Dec 22, 2008 at 2:55 PM, John Peterson < peterson@...> wrote: > Hey, > > Not sure if this is it but could you try: > > void Parameters::Parameter<typename std::vector<T> >::print > (std::ostream& os) const > > (just add the typename qualifier, everything else the same.) Anyway, > that is what I always try when I'm dealing with templates and there is > a type which depends on T... > > -- > John > > > > On Mon, Dec 22, 2008 at 2:38 PM, Derek Gaston <friedmud@...> wrote: > > Ok - I give up... someone tell me what the hell I'm doing wrong. I'm > trying > > to add the following function to parameters.h (right underneath the > generic > > version): > > template <typename T> > > inline > > void Parameters::Parameter<std::vector<T> >::print (std::ostream& os) > const > > { > > for (unsigned int i=0; i<_value.size(); i++) > > os << _value[i] << " "; > > } > > And I get errors: > > invalid use of undefined type 'class Parameters::Parameter<std::vector<T, > > std::allocator<_CharT> > >' > > /Users/gastdr/projects/libmesh/include/utils/parameters.h:163: error: > > declaration of 'class Parameters::Parameter<std::vector<T, > > std::allocator<_CharT> > >' > > /Users/gastdr/projects/libmesh/include/utils/parameters.h:260: error: > > template definition of non-template 'void > > Parameters::Parameter<std::vector<T, std::allocator<_CharT> > > >>::print(std::ostream&) const' > > /Users/gastdr/projects/libmesh/include/utils/parameters.h: In member > > function 'void Parameters::Parameter<std::vector<T, > std::allocator<_CharT> > > >>::print(std::ostream&) const': > > > > But... if I do: > > template <> > > inline > > void Parameters::Parameter<std::vector<Real> >::print (std::ostream& os) > > const > > { > > for (unsigned int i=0; i<_value.size(); i++) > > os << _value[i] << " "; > > } > > Like normal template specialization.... it works fine. I've tried > looking > > this up in various places.... and from what I can see I'm doing it > > correctly.... so it's time for some outside advice. I've also tried > > hundreds of permutations.... and just can't get the damn thing to go. > > Thanks! > |
From: Derek Gaston <friedmud@gm...> - 2008-12-22 23:46:21
Attachments:
Message as HTML
|
Well... I've found a workaround. It turns out that I can just inject my own template specializations into the global namespace.... and they will get picked up by the compiler. So I just made specializations for std::vector<Real> and std::vector<std::vector<Real> >.... and it works. This way I don't have to modify libMesh. Still wish I could figure out the proper syntax there though... Derek On Mon, Dec 22, 2008 at 4:39 PM, Derek Gaston <friedmud@...> wrote: > I've done similar things in the past... but that isn't working in this > case. In particular I get: > error: using 'typename' outside of template > error: 'T' was not declared in this scope > > Sigh. > > Derek > > On Mon, Dec 22, 2008 at 2:55 PM, John Peterson < > peterson@...> wrote: > >> Hey, >> >> Not sure if this is it but could you try: >> >> void Parameters::Parameter<typename std::vector<T> >::print >> (std::ostream& os) const >> >> (just add the typename qualifier, everything else the same.) Anyway, >> that is what I always try when I'm dealing with templates and there is >> a type which depends on T... >> >> -- >> John >> >> >> >> On Mon, Dec 22, 2008 at 2:38 PM, Derek Gaston <friedmud@...> wrote: >> > Ok - I give up... someone tell me what the hell I'm doing wrong. I'm >> trying >> > to add the following function to parameters.h (right underneath the >> generic >> > version): >> > template <typename T> >> > inline >> > void Parameters::Parameter<std::vector<T> >::print (std::ostream& os) >> const >> > { >> > for (unsigned int i=0; i<_value.size(); i++) >> > os << _value[i] << " "; >> > } >> > And I get errors: >> > invalid use of undefined type 'class >> Parameters::Parameter<std::vector<T, >> > std::allocator<_CharT> > >' >> > /Users/gastdr/projects/libmesh/include/utils/parameters.h:163: error: >> > declaration of 'class Parameters::Parameter<std::vector<T, >> > std::allocator<_CharT> > >' >> > /Users/gastdr/projects/libmesh/include/utils/parameters.h:260: error: >> > template definition of non-template 'void >> > Parameters::Parameter<std::vector<T, std::allocator<_CharT> > >> >>::print(std::ostream&) const' >> > /Users/gastdr/projects/libmesh/include/utils/parameters.h: In member >> > function 'void Parameters::Parameter<std::vector<T, >> std::allocator<_CharT> > >> >>::print(std::ostream&) const': >> > >> > But... if I do: >> > template <> >> > inline >> > void Parameters::Parameter<std::vector<Real> >::print (std::ostream& os) >> > const >> > { >> > for (unsigned int i=0; i<_value.size(); i++) >> > os << _value[i] << " "; >> > } >> > Like normal template specialization.... it works fine. I've tried >> looking >> > this up in various places.... and from what I can see I'm doing it >> > correctly.... so it's time for some outside advice. I've also tried >> > hundreds of permutations.... and just can't get the damn thing to go. >> > Thanks! >> > > |