[Development] Fornux C++ Superset
philippeb8 at gmail.com
Thu Apr 26 05:35:46 CEST 2018
On 04/25/2018 09:45 AM, Eric Lemanisser wrote:
> What about
> void foo(int (&array))
This one works fine:
void foo(int (&array))
cout << __PRETTY_FUNCTION__ << endl;
void foo(const boost::node_proxy &, boost::root_array<std::vector<int>,
> 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;
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.
More information about the Development