M
Marcel Müller
Is the following code valid?
#include <stdlib.h>
#include <ostream.h>
// compare *l to *r
template <class T>
int comparer(const T* l, const T* r)
{ if (*l < *r)
return -1;
return *l == *r;
}
// Returns true on match, pos receives the lower bound.
template <class T>
int binary_search(const T* data, size_t len, int (*fcmp)(const T* elem,
const T* key), const T* key, size_t& pos)
{ // does not care
pos = 0;
return 0;
}
int foo(int key)
{ const int arr[] = {1,2,3,4};
size_t pos;
return binary_search(&*arr, sizeof arr/sizeof *arr, &comparer<int>,
&key, pos)
^
? pos : ~pos;
}
int main()
{ cout << foo(3);
return 0;
}
One of my compilers says
test2.cpp(24:68) : error EDC3090: Syntax error - expected "(" and
found ">".
at the marked position.
Marcel
#include <stdlib.h>
#include <ostream.h>
// compare *l to *r
template <class T>
int comparer(const T* l, const T* r)
{ if (*l < *r)
return -1;
return *l == *r;
}
// Returns true on match, pos receives the lower bound.
template <class T>
int binary_search(const T* data, size_t len, int (*fcmp)(const T* elem,
const T* key), const T* key, size_t& pos)
{ // does not care
pos = 0;
return 0;
}
int foo(int key)
{ const int arr[] = {1,2,3,4};
size_t pos;
return binary_search(&*arr, sizeof arr/sizeof *arr, &comparer<int>,
&key, pos)
^
? pos : ~pos;
}
int main()
{ cout << foo(3);
return 0;
}
One of my compilers says
test2.cpp(24:68) : error EDC3090: Syntax error - expected "(" and
found ">".
at the marked position.
Marcel