On 04/25/2018 09:45 AM, Eric Lemanisser wrote:
What about
void foo(int (&array)[3])
This one works fine:
void foo(int (&array)[10])
{
cout << __PRETTY_FUNCTION__ << endl;
}
int main()
{
int array[10];
foo(array);
return 0;
}
Correctly outputs:
void foo(const boost::node_proxy &, boost::root_array<std::vector<int>,
10> (&))
and
template<int N>
void foo(int (&array)[N]) ?
Since I just started testing C++98 as of last week, I haven't yet had a
chance to test templates thoroughly. So this one is buggy and I'll have
to fix it.
Both of these functions make sure the caller and the callee use the same
array size at compile time. I don't see anybody giving away this kind of
security, especially fro functions called across translation units. Does
your system store the length of the array next to the pointer at runtime
? What is the cost of this ?
root_array<> looks like this:
template <typename T, size_t S>
class root_array : public boost::root_ptr<T>
{
typedef boost::root_ptr<T> base;
public:
root_array(base const & p) : base(p)
{
}
root_array(boost::node_proxy const & __y) : base(__y, "",
boost::create<typename T::value_type>()(__y, S))
{
}
[...]
};
So it knows the length of the array at compile-time but it really
creates a root_ptr pointing to a std::vector of size S allocated at
runtime. This is the lowest common factor necessary to make a smooth
conversion to a root_ptr.
Regards,
-Phil
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development