Why won't this template function compile?

Hi,

Here's the minimal program illustrating the "mystery":

#include <vector>
using namespace std;

template <typename T>
T silly_f (typename vector<T>::const_iterator begin,
           typename vector<T>::const_iterator end)
{
    return *begin;
}

int main()
{
    vector<int> values;
    silly_f (values.begin(), values.end());

    return 0;
}

With g++ 4.1.1, I get an error in the line that calls the function ---
it tells
me "no match for call to silly_f ( ..... iterator .... ,  .....
iterator ...) --- g++
3.3.3 also gives me the same error

(the .... refers to the expanded gibberish for vector<int>::iterator )

I know that the "better" solution is to do:

template <typename Iterator>
typename Iterator::value_type silly_f (Iterator begin, Iterator end)

(not only it is better and more elegant --- it also compiles)

But I'm puzzled and would like to find out why won't the other
version compile.

Thanks,

Carlos
--


--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
cm_news (6)
4/17/2007 5:55:07 PM
comp.lang.c++.moderated 10705 articles. 11 followers. allnor (8507) is leader. Post Follow

13 Replies
220 Views

Similar Articles

[PageSpeed] 50
On 4��18��, ����7ʱ55��, Carlos Moreno <cm_n...@mailinator.com> wrote:
> Hi,
>
> Here's the minimal program illustrating the "mystery":
>
> #include <vector>
> using namespace std;
>
> template <typename T>
> T silly_f (typename vector<T>::const_iterator begin,
>            typename vector<T>::const_iterator end)
> {
>     return *begin;
>
> }
>
> int main()
> {
>     vector<int> values;
>     silly_f (values.begin(), values.end());
>
>     return 0;
>
> }
I think it is because the compiler can't deduce the type for the
function. just do like below:
 int main()
 {
     vector<int> values;
     silly_f <int> (values.begin(), values.end());

     return 0;
 }



--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
zade
4/17/2007 10:47:38 PM
> > Here's the minimal program illustrating the "mystery":
> [...]
> > template <typename T>
> > T silly_f (typename vector<T>::const_iterator begin,
> >            typename vector<T>::const_iterator end)
> [...]
> > int main()
> > {
> >     vector<int> values;
> >     silly_f (values.begin(), values.end());
>  [...]
>
>      vector<int> values;
>      silly_f <int> (values.begin(), values.end());

Still does not compile  (same error message!!) --- which makes it
even more puzzling.  I thought it would compile, and I was still
going to ask:  "but why won't the other one compile?"  That is,
my interest is not really in making it work --- there is the better
solution anyway, doing template <typename Iterator> --- but
rather in understanding why is it that the compiler won't deduce
and won't see a match, even if we deduce it for the compiler?
Anyone?

Thanks,

Carlos
--


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Carlos
4/18/2007 8:57:25 AM
On Apr 18, 12:55 am, Carlos Moreno <cm_n...@mailinator.com> wrote:
> Hi,
>
> Here's the minimal program illustrating the "mystery":
>
> #include <vector>
> using namespace std;
>
> template <typename T>
> T silly_f (typename vector<T>::const_iterator begin,
>            typename vector<T>::const_iterator end)
> {
>     return *begin;
>
> }
>
> int main()
> {
>     vector<int> values;
>     silly_f (values.begin(), values.end());
>
>     return 0;
>
> }
>
> With g++ 4.1.1, I get an error in the line that calls the function ---
> it tells
> me "no match for call to silly_f ( ..... iterator .... ,  .....
> iterator ...) --- g++

values.begin() is of type vector<int>::iterator, not of type
vector<int>::const_iterator.  Thus the compiler can't match the type
of the first argument and can't deduce the template argument.


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Martin
4/18/2007 8:57:47 AM
On 18 Apr, 15:57, Carlos Moreno <cm_n...@mailinator.com> wrote:
> > > Here's the minimal program illustrating the "mystery":
> > [...]
> > > template <typename T>
> > > T silly_f (typename vector<T>::const_iterator begin,
> > >            typename vector<T>::const_iterator end)
> > [...]
> > > int main()
> > > {
> > >     vector<int> values;
> > >     silly_f (values.begin(), values.end());
> >  [...]
>
> >      vector<int> values;
> >      silly_f <int> (values.begin(), values.end());
>
> Still does not compile  (same error message!!)

This does compile with gcc 3.4.4 and 4.1.2.

>  "but why won't the other one compile?"

Because the standard says so in 14.8.2.4/4.
    -4- The nondeduced contexts are:
        * The nested-name-specifier of a type that was
          specified using a qualified-id.
        ...
The compiler is forbidden to try and deduce the type T. But, even
if it wasn't, how could it, without the explicit knowledge of
std::vector,
tell that T=int is a match? And more, how could it tell that it's the
_only_ match?

Regards
Vladimir Marko


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Vladimir
4/18/2007 10:53:07 AM
> > template <typename T>
> > T silly_f (typename vector<T>::const_iterator begin,
> >            typename vector<T>::const_iterator end)

> values.begin() is of type vector<int>::iterator, not of type
> vector<int>::const_iterator.  Thus the compiler can't match the type
> of the first argument and can't deduce the template argument.

D'oh!  I would have sworn that I copy-n-pasted, but apparently I
didn't,
since in my code, I used iterator, and not const_iterator" ...
(sorry
about that!  I shouldn't make these types of trivial mistakes!)

Ok, now I'm going to copy-n-paste the entire file, and post the
*exact*
error message:

---  BEGIN FILE test.c++  ---
#include <vector>
using namespace std;

template <typename T>
T silly_f (typename vector<T>::iterator begin,
           typename vector<T>::iterator end)
{
    return *begin;
}

int main()
{
    vector<int> values;
    silly_f (values.begin(), values.end());

    return 0;
}
---  END FILE test.c++  ---

Compiled with:  c++ -c test.c++

test.c++: In function 'int main()':
test.c++:14: error: no matching function for call to
'silly_f(__gnu_cxx::__normal_iterator<int*, std::vector<int,
std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >)'

Now, the funny thing is:  with the previous poster's suggestion
(calling it
like  silly_f<int> ( ... ) ), then it does compile  (I was on another
computer
and I copy-n-pasted from what I had posted --- so now, the error was
due
to the const_iterator vs. iterator).

So, the mystery is still on ...  (compiler bug?  I still refuse to
believe that
this may be the case --- g++ is notoriously good at template stuff;
this
one seems like a particularly trivial bug when it comes to templates,
so
it would be quite surprising)

Is it possible that it is related to the nested-type-in-a-template
issue?
The same reason why we need to "help" the compiler, using the keyword
typename so that it knows that vector<T>::iterator refers to a type?
Even if that's the case, I don't know ...  Seems like a trivial match
to
deduce...

Thanks,

Carlos
--



-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Carlos
4/18/2007 11:44:20 AM
> > >      silly_f <int> (values.begin(), values.end());
>
> > Still does not compile  (same error message!!)
>
> This does compile with gcc 3.4.4 and 4.1.2.

Silly error from my part --- see my other post in this sub-thread.

> >  "but why won't the other one compile?"
>
> Because the standard says so in 14.8.2.4/4.
>     -4- The nondeduced contexts are:
>         * The nested-name-specifier of a type that was
>           specified using a qualified-id.

Hmmm, is this really the case??  I'm probably confused about the
terminology, but the nested-name is iterator, and not T  (iterator
was qualified with the scope-resolution operator).

> The compiler is forbidden to try and deduce the type T. But, even
> if it wasn't, how could it, without the explicit knowledge of
> std::vector,
> tell that T=int is a match? And more, how could it tell that it's the
> _only_ match?

And who said that the compiler has no explicit knowledge of
std::vector??  I #included <vector>, where the compiler finds
everything that it ever may need to know about vector  (not to
mention the issue that, since vector is fully documented in the
standard, why wouldn't the compiler assume knowledge about
it? --- well, ok, this is an entirely separate discussion, so let's
say that we avoid that tangent)

The thing is, putting aside the fact that the standard says that
there is no match --- I don't see why it could not see that match
(seems obvious enough for you;  maybe it's related to the way
compilers are implemented?  An area which I'm 150% unfamiliar
with!) ...

The given type is known --- vector<int>::iterator;  an available
template has been given, and fully described/visible to the
compiler, since #include <vector> is present;  the available
template has a type member iterator;  this constitutes a match
for vector<int>::iterator  given by  vector<T>::iterator for T=int.

Why would the compiler not know, or not know that it is the
only match?

Carlos
--




-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Carlos
4/18/2007 1:46:36 PM
Carlos Moreno wrote:
::
:: And who said that the compiler has no explicit knowledge of
:: std::vector??  I #included <vector>, where the compiler finds
:: everything that it ever may need to know about vector  (not to
:: mention the issue that, since vector is fully documented in the
:: standard, why wouldn't the compiler assume knowledge about
:: it? --- well, ok, this is an entirely separate discussion, so let's
:: say that we avoid that tangent)
::
:: The thing is, putting aside the fact that the standard says that
:: there is no match --- I don't see why it could not see that match
:: (seems obvious enough for you;  maybe it's related to the way
:: compilers are implemented?  An area which I'm 150% unfamiliar
:: with!) ...
::
:: The given type is known --- vector<int>::iterator;  an available
:: template has been given, and fully described/visible to the
:: compiler, since #include <vector> is present;  the available
:: template has a type member iterator;  this constitutes a match
:: for vector<int>::iterator  given by  vector<T>::iterator for T=int.
::
:: Why would the compiler not know, or not know that it is the
:: only match?

The problem is that the compiler cannot know that vector<int>::iterator is
different from all other vector<T>::iterator, until it has tried to
instantiate std::vector for ALL possible values of T.

What if I have:

struct MySillyType
{ };

template<>
class std::vector<MySillyType>
{
     typedef std::vector<int>::iterator   iterator;
};

Now silly_f<int>() and silly_f<MySillyType>() has the same signature. 
How is
the compiler to know? It just cannot!


Bo Persson






-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Bo
4/18/2007 11:09:45 PM
Carlos Moreno schrieb:
> > > template <typename T>
> > > T silly_f (typename vector<T>::const_iterator begin,
> > >            typename vector<T>::const_iterator end)
>
> > values.begin() is of type vector<int>::iterator, not of type
> > vector<int>::const_iterator.  Thus the compiler can't match the type
> > of the first argument and can't deduce the template argument.
>
> D'oh!  I would have sworn that I copy-n-pasted, but apparently I
> didn't,
> since in my code, I used iterator, and not const_iterator" ...
> (sorry
> about that!  I shouldn't make these types of trivial mistakes!)

Note that your problem has *nothing* to do with choosing
vector<T>::iterator over vector<T>::const_iterator (that is only
relevant for your internal logic).
Vladimir Marko has given the correct answer: Your are defining
your function template in a way that all function parameters are in
a nondeduced context. In this situation 14.8.2.4/3 applies:

"[..] If a template parameter is used only in nondeduced contexts
and is not explicitly specified, template argument deduction fails."

So in your situation you *must* explicitly provide the argument
type. After doing this the code will compile with either
vector<T>::iterator or vector<T>::const_iterator, because
the vector<T>::iterator is valid and convertible to
vector<T>::const_iterator.

> Now, the funny thing is:  with the previous poster's suggestion
> (calling it
> like  silly_f<int> ( ... ) ), then it does compile  (I was on another
> computer
> and I copy-n-pasted from what I had posted --- so now, the error was
> due
> to the const_iterator vs. iterator).

As explained above in this situation explicitely specifying
the template argument type is required and not optional.

> The same reason why we need to "help" the compiler, using the keyword
> typename so that it knows that vector<T>::iterator refers to a type?
> Even if that's the case, I don't know ...  Seems like a trivial match
> to
> deduce...

It has no relation to provide a "typename" in front of a dependent
qualified-id. The reason is that it is in general impossible to deduce
the "base" (or parts of it) from a qualified-id of the actually
qualified
"leaf". Assume that std::vector<int>::iterator is int*. Given the int*
as
result, how do you unambigiously deduce the leading std::vector<int>?

Greetings from Bremen,

Daniel Kr�gler



-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
iso
4/18/2007 11:10:17 PM
Carlos Moreno wrote:
> Even if that's the case, I don't know ...  Seems like a trivial match
> to deduce...

As has already been posted, T is not deducible from the
arguments. You can read the standard for chapter and verse,
but the basic problem is that there can be an infinite
number of matches. Here's why - I can write a specialization
like this:

class a { };
template <>
class std::vector<a> {
public:
     typedef vector<int>::iterator iterator;
};

This makes vector<int>::iterator and vector<a>::iterator be
the same type, so you can see why simply having the iterator
doesn't let you go back to the type parameter.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Hyman
4/18/2007 11:11:01 PM
Hyman Rosen wrote:
> class a { };
> template <>
> class std::vector<a> {
> public:
>     typedef vector<int>::iterator iterator;
> };

The actual legal syntax for the above would be
     #include <vector>
     class a { };
     namespace std {
         template <> class vector<a> {
         public: typedef vector<int>::iterator iterator;
         };
     }
Sorry about that.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Hyman
4/19/2007 11:01:29 AM
> The problem is that the compiler cannot know that vector<int>::iterator is
> different from all other vector<T>::iterator, until it has tried to
> instantiate std::vector for ALL possible values of T.

Ok --- this is the key element that I was failing to see!!  (looked
like a
trivial match because I was looking just at a sub-set of the
scenario!)

Still --- and please, do not take the following as me being dense;
just
enjoying the discussion just for the sake of working the ideas:

> struct MySillyType
> { };
>
> template<>
> class std::vector<MySillyType>
> {
>      typedef std::vector<int>::iterator   iterator;
>
> };
>
> Now silly_f<int>() and silly_f<MySillyType>() has the same signature.
> How is
> the compiler to know? It just cannot!

What do you mean it can not??  We can --- and I mean, our brains do
determine in an *fully objective* and completely unambiguous and
undebatable way, if there is a match or there is ambiguity.  Why
wouldn't the compiler be able to?

I mean, the issue is:  if two instances of vector<T>::iterator are
the
same, then the call would be ambiguous --- nothing new there:  but
if the compiler only sees the one definition (by means of a *generic*
without any specialized definition) that could match, then where's
the problem?

If two iterators for two different instances of vector<T> are the
same,
the compiler should see it --- if you are in a context where the
vector<MySillyType> counts, then the definition of SillyType and
that of vector<SillyType> will have been seen.  If they have been
seen, then the compiler will (rightfully) declare ambiguity.

And if they (SillyType and vector<SillyType> have not been seen, then
the match for the call that the compiler is seeing (in the main
program)
can not be that for SillyType, nor it would matter that the compiler
did
not consider SillyType as a candidate match.

What am I missing?

(no, I'm not missing the fact that the standard simply says that the
compiler won't do it --- that part is already understood and
accepted;
my argument now goes around the rationale about why is it not
possible
for the compiler to deduce the template parameter in these types of
situations --- simply curious/puzzled, not trying to be dense)

Thanks,

Carlos
--


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Carlos
4/19/2007 1:43:15 PM
Carlos Moreno wrote:
> We can ... if there is a match or there is ambiguity.
> Why wouldn't the compiler be able to?
> What am I missing?

You're failing to generalize from the examples given.
Perhaps this will make it more clear:

     template <typename T> struct X { typedef char (&t)[sizeof(T)]; };
     template <typename U> void f(typename X<U>::t);
     void g(X<int>::t a) { f(a); }

Can you see why the compiler cannot deduce U from f's argument?

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Hyman
4/19/2007 3:40:59 PM
Carlos Moreno wrote:
>> struct MySillyType
>> { };
>>
>> template<>
>> class std::vector<MySillyType>
>> {
>>      typedef std::vector<int>::iterator   iterator;
>>
>> };
>>
>> Now silly_f<int>() and silly_f<MySillyType>() has the same signature.
>> How is
>> the compiler to know? It just cannot!
> 
> What do you mean it can not??  We can --- and I mean, our brains do
> determine in an *fully objective* and completely unambiguous and
> undebatable way, if there is a match or there is ambiguity.  Why
> wouldn't the compiler be able to?

Not really, we can tell there is ambiguity only beacause the example is 
so trivial. In general, however, it is algorithmically impossible to 
decide whether there is an ambiguity or not. I spent the last few hours 
learning Boost.Mpl so I could prove it :-) --- in the following code, 
'post_checker<I, S>::type' is 'true_' if and only if 'S' is a solution 
of the Post correspondence problem 'I' or 'S' is 'true_'. Hence, the 
deduction in call to 'foo(true_())' would be ambiguous iff the problem 
'instance' had a solution.

Since it is impossible to decide whether a given Post correspondence 
problem has a solution, the compiler can say nothing about the ambiguity 
of type deduction in call to 'foo(true_())'.

#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/at.hpp>
using namespace boost::mpl;

template <class Instance, class Solution>
struct post_checker
{
     typedef
         typename reverse_fold<
             Solution,
             vector<>,
             insert_range<_1, begin<_1>,
                 at<typename first<Instance>::type, _2> >
         >::type left_word;

     typedef
         typename reverse_fold<
             Solution,
             vector<>,
             insert_range<_1, begin<_1>,
                 at<typename second<Instance>::type, _2> >
         >::type right_word;

     typedef typename equal<left_word, right_word>::type type;
};

template <typename Instance>
struct post_checker<Instance, true_>
{
     typedef true_ type;
};

// This is an instance of the Post correspondence problem,
// the sequences are ("aba", "bbb", "aab", "bb") and
// ("a", "aaa", "abab", "babba"). For the record,
// the instance has a solution and that is (0, 3, 2, 0)
// if we're indexing from zero. The example was taken
// from Wikipedia page on PCP.
typedef
     pair<
         vector<
             vector_c<char, 'a', 'b', 'a'>::type,
             vector_c<char, 'b', 'b', 'b'>::type,
             vector_c<char, 'a', 'a', 'b'>::type,
             vector_c<char, 'b', 'b'>::type
         >,
         vector<
             vector_c<char, 'a'>::type,
             vector_c<char, 'a', 'a', 'a'>::type,
             vector_c<char, 'a', 'b', 'a', 'b'>::type,
             vector_c<char, 'b', 'a', 'b', 'b', 'a'>::type
         >
     >
     instance;

template <typename Solution>
void foo(typename post_checker<instance, Solution>::type)
{
}

int main()
{
     // If the standard allowed the deduction,
     // would it be ambiguous in the call below?
     //
     // foo(true_());

     // Test the correctness of post_checker...
     foo<true_>(true_());
     foo<vector_c<int, 0, 3, 2, 0> >(true_());
     foo<vector_c<int, 0, 3, 2, 1> >(false_());
}

-- 
Best regards,
Martin Vejn�r


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
ISO
4/26/2007 4:12:09 PM
Reply:
Similar Artilces:

explicit templates instantiation .... more
///// 1 Consider the _FUNCTION_ template template <typename T> int spaceOf () { int bytes = sizeof T; return bytes / 4 + bytes % 4 > 0; } Since C++ templates requires more intelligence from the environment 'we' have to tell the compiler about the actualy type: So now: class C {}; typdef void (*ptrFun)(int); int idx = spaceOf<C>(); int jdx = spaceOf<ptrFunc>(); Except how do i achieve the same feat here for this fuction template: class D { public: template<typename T> // here we go again.... D( T& t, void(T::*f)() ) {} }; class U...

compiling object files from Iron Spring PL/I on Linux
Im just a hobbiest programmer trying to learn PL/I and so far Iron Spring is the only free PL/I compiler I can find that runs on x86. It only produces .obj files with the -C flag and Im wondering how I can link that into an executeable binary file in Linux. Ive tried: ld filename.o -o filename and that did not work. Could someone tell me how I link the object files? and does IBM provide a free PL/I compiler for x86? -dELF. There's a bug that causes the complier to default to .obj files in Linux as well as OS/2. Brad Cantrell wrote: > Im just a hobbiest programmer trying to learn P...

"inline-assembly/C++ template" issue
Hi All, We can have textual substitution inside ASM, but i am getting error only for first substitution. Please do let me know how to solve it. template.cc:109:27: error: expected string-literal before 'right_string' asm volatile ( right_string<T>::instr_str ^ //////////////////////////////////////////////////////////////////////////////////// template < > struct right_string<signed char> { static constexpr const char * instr_str = "mov %2, %%bh \n\tinc %%bh \n\tmov %%bh, %0 \n\tpushf ...

difference between formal and functional verification
Sorry for a dumbo. But I am a s/w guy since I am working on the compiler basics of a simulator, I keep hearing about the functional and formal verification . What is the difference between the two. Can somebody please explain to me ? Also . what are cycle based semantics. What can be other semantics that are used by the verification tools? On Mar 6, 2:49 pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com> wrote: > Sorry for a dumbo. > But I am a s/w guy since I am working on the compiler basics of a > simulator, I keep hearing about the functional...

Templates templates templates
The following compiles: #include <iostream> using std::cout; using std::endl; template< class T > struct DisplayFormat { unsigned char radix; const T* digits; T decimal_point_symbol; unsigned char digits_after_decimal_point; T comma_symbol; unsigned char digits_until_comma; }; DisplayFormat<wchar_t> us_display_format = { 10 , L"0123456789" , L'.' , 2 , L',' , 3 }; template < DisplayFormat < wchar_t > * df> //THIS LINE inline void Blah() { cout << df->digits << endl; } int main...

How to generate proper seeds for the rand function in Monte Carlo simulations? #2
Dear all, I'm trying to evaluate results of an non-deterministic algorithm using a number of Monte Carlo simulations (e.g. 100). The algorithm is using these lines at the beginning of the code: rand('state', mySEED) randn('state', mySEED) I need to repeat the MC simulations for different parameters, therefore those 100 seeds (mySEEDs) must be known to me for next experiments. Could you please tell me how to generate those seeds? I've found randseed() and it seems fine (e.g. randseed(mySTATE,100)), but I'm not sure what the proper value for the my...

Sun Microsystems and templates
Anyone have any idea on whether Sun is EVER going to get around to implementing template template parameters? I keep looking for the line "" Template template parameters (templates as template parameters)"" to disappear from the Standards Not Implemented section of the C++ README. It makes it kind of hard to use the moderncpp stuff from Loki, specifically policy classes. Anyone have any recommendations on a *good* way to work around this - without changing compiler vendors? ash [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ com...

defining a global variable in a c s function
i could not create a global variable in a c s function.i do want to take as input and output a variable.so i decided to define a global variable. is there a way to do.thanks.. ...

and/or functions revisited
Yesterday I posted asking about the possible existence of and/or functions (instead of macros) to be used for higher-order functional programming (fancy words ... justed wanted to play with these things passing them around as arguments, something you can't do with macros). I really wanted to thank everyone for the very helpful suggestions. After reading them, I finally decided to give it a shot (after all isn't that what lisp is all about? :) ) and roll my own: (define (andf . args) (let loop ((lst args)) (cond ((null? lst) #t) ((not (car lst)) #f) (else (lo...

template matching #11
I have collected images of proteins from protein data bank.I need to do template matching on the images.Can anyone help me out. On Jan 11, 10:59=A0am, "sanyukta " <sanyuktacheti...@gmail.com> wrote: > I have collected images of proteins from protein data bank.I need to do t= emplate matching on the images.Can anyone help me out. ------------------------------------------------------------------- Are you looking for something like this: http://www.mathworks.com/matlabcentral/answers/24467-identifying-objects-in= -a-picture-containing-several-objects ...

SQL 2012 CLR Function Causing Error:
We are in the process of migrating our SQL 2008 R2 Enterprise Edition environment to a new SQL Server 2012 Enterprise Edition. Both current and the new environments are Active / Passive SQL cluster and I have been running a CLR function on the existing environment which I am trying to migrate. The function returns fine most of the time, but at intermittent times, its giving me the following error: Msg 6522, Level 16, State 1, Line 3 A .NET Framework error occurred during execution of user-defined routine or aggregate "<FunctionName>": System.ApplicationExceptio...

XSLT one tamplate opens tag second template closes
Hello everybody. I've got a problem with creating a universal stylesheet eg: <xsl:template match="/"> <xsl:call-template name="header"/> <xsl:apply-templates select="/data/content"/> <xsl:call-template name="footer"/> </xsl:template> inside header tamplate I've got sth like this: <xsl:template name="header"> <html> <head> <title> <xsl:value-of select="$Title"/> </title> </head> <body> </xsl:template> as You can see the html and body tags a...

65535 limitation for methods / functions / constructor
Can anybody answer me the question if there is any possiblity to increase the 65535byte limitation for Java classes / methods / functions / constructors etc. I am currently researching in the field of Bayesian Networks. BN is a special Knowledge representation which uses calculation via conditional probabilities to come to a conclusion (out of some data). The problem is that these Networks need a huge amonge of dependet data. One of the BN Engines i am using wants to get the data input by a class file. Some of these datas are also stored in an array of doubles ( please dont ask me ...

function key
I know th ...

Compiling C++ Templates as opposed to Preprocessing them.
Hi, Can readers of this forum advise on whether it would be fruitful to consider compiling C++ templates to IR instead of preprocessing them? Consider the following snippet: template<class T> void foo(const T &t) { T::i; // #1 } Since the compiler cannot tell if `i' is a static member of `T', an extra operator needs to be introduced in the IR so that the `::' operator can be mapped to it. This operator would have no use in a non-generic scope, therefore, that operator is there merely to represe...

HOPE: A Python just-in-time compiler for astrophysical computations
Another beasty I've just stumbled across which you may find interesting http://www.sciencedirect.com/science/article/pii/S2213133714000687 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence On 21/06/2015 01:29, Mark Lawrence wrote: > Another beasty I've just stumbled across which you may find interesting > http://www.sciencedirect.com/science/article/pii/S2213133714000687 Blimey, that's a lot of waffle in there, but I suppose that's to be expected from a published paper. I think ...

Function linkage and ADL in templates
Consider the following program: typedef char size_1[1]; typedef char size_2[2]; typedef char size_3[3]; // has external linkage in both C++03 and N3225 size_1 &f(...); template <class T> void g(T *p) { char arr[sizeof(f(p)) == 2]; } namespace // unnamed { struct X {}; // has external linkage in C++03 // and internal linkage in N3225 size_2 &f(void *); // has internal linkage in both C++03 and N3225 static size_3 &f(X *); } int main() { X ...

FTP Function just wont work! help!
Hey all, First up, I am a newb, so go easy on me! I am having issues with the FTP Function ... I have read MANY posts on similar problems, but have found no fixes that seem to work (for me at least) ... I have pretty much cut and paste the FTP example from PHP.net. The code connects to and logs into the FTP server fine, but never uploads anything! Bellow is my form code to retrieve the source file name : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <form name='ftpUpload' method='post' action='ftp.php'> <input type='...

NVU Mambo 4.5.x Template Builder v0.0.9beta Released!
NVU Mambo Template Builder will make automatic your mambo template creation. Make easy and productive your Mambo template building! NVU Mambo Template Builder will make automatic your templateDetails.xml creation and updates,your Template directory structure creation,it will create blank index.html files on "css and images" dirs, allow easily insert mambo 4.5.3 specific Template PHP code needed to build your Mambo template and build a zip install package ready to install on your Mambo. NVU is complete Web Authoring System for Linux Desktop users as well as Windows and Mac ...

Can a template function return a template type?
Hi, Created the template function below but the g++ compiler keeps complaining "no matching function for call to....". Is there a way to make it work? Thank you. ==========snip part of class method=========== template <class TYPE> TYPE *field( const std::string &field_name ) { if( !b_default ) { throw runtime_error("{persistent}<field>: Not in default " "mode, cannot use the field method!"); } std::map<std::string, std::vector<std::string> >::iterator iter; iter = m_table.find( fie...

Curious template behavior, g++ and xlC and icpc
Hi, Consider this code fragment, based on the article "Using Chains to Free Library Code" from the July 2005 issue of C/C++ Users Journal: -- begin listing -- template <class T> struct Foo { template <class S> struct Bar : public Foo<S> { }; }; int main() { Foo<double>::Bar<int> x; Foo<int>::Bar<double>::Bar<char*> y; return 0; } -- end listing -- g++ and icpc compiles this bit of code without complaint. xlC, on the other hand, has trouble with resolving the names and returns the error: "test.cpp&q...

fft function #4
Hi! I have used fft function to make the power spectrum of a frequency sweep acquired with Fs=1000Hz (211001 points). I have wrote: > xfft=fft(input,211000); >> Pxfft = xfft.* conj(xfft) / 211000; >> f = 1000*(0:105500)/211000; plot(f,Pxfft(1:105501)) title('Frequency content of input') xlabel('frequency (Hz)') but the spectrum is completely wrong. Where is my error? Thanks in advance, Fab Fabrizio Forni wrote: > > > Hi! > I have used fft function to make the power spectrum of a frequency > sweep > acquired with Fs=1000Hz (211...

Undefined virtual Function Table
Hi, I am currently working on a big project, and I usually don't post to newsgroups as I like to get through problems on my own, or by talking to coworkers. However, I have recently run across a problem that I am unable to resolve using the tools that I have available: While compiling an executable on the Sun-Solaris OS Version 2.4 using gcc 2.8.1 and either the native sun linker or the ld that comes with binutils 2.9.1 we receive an undefined symbol: __vt_8NewClass which demangles to 'TrackFiles virtual table' I have read that (On platforms that r...

What is the licensing status of Fig-Forth v 2.32? Are Forth compilers generally safe?
This is a shareware compiler, and the notes say that one is required to purchase it if it is found useful, but on the other hand it also says that one can freely distribute programs made with it, if there is no commercial usage. So, if I distribute freeware, am I still required to purchase it? Here's the link to the compiler: http://www.simtel.net/product.php%5Burl_fb_product_page%5D63060 Another question, and this come from someone who has never written a line of assembly; is it safe to use forth compilers as F-PC, pygmy and Turbo-Forth? I can't possibly damage my computer perm...

FAQ Topic
----------------------------------------------------------------------- FAQ Topic - What is a function statement? ----------------------------------------------------------------------- The term function statement has been widely and wrongly used to describe a `FunctionDeclaration`. This is misleading because in ECMAScript, a `FunctionDeclaration` is not a Statement; there are places in a program where a Statement is permitted but a `FunctionDeclaration` is not. To add to this confusion, some implementations, notably Mozillas', provide a syntax extension called function statement...