[array][bind] Binding boost array to a boost function

I'm trying to bind a boost array to be called at a later time. This is giving me a lot of errors. Is what I'm attempting possible? Ryan template<typename T, std::size_t U> class Sorter { private: typedef boost::function<void(boost::array<T, U> & a)> t_SortFunction; t_SortFunction m_SortFunction; public: Sorter(t_SortFunction func) : m_SortFunction(func) {} bool sort(boost::array<T, U> & a) { m_SortFunction(a); } }; template<typename T, std::size_t U> void quicksort(boost::array<T, U> & a) { } int main(int argc, char* argv[]) { Sorter shell(boost::bind(quicksort, _1)); return 0; }

Am 11.10.2010 01:59, schrieb Ryan McConnehey:
Is what I'm attempting possible?
Ryan
Hi, yes it is, but you need to pass the template-parameters: Sorter<int, 8> shell(boost::bind(quicksort<int, 8>, _1)); or simply Sorter<int, 8> shell(quicksort<int,8>); Regards, michi7x7
template<typename T, std::size_t U> class Sorter { private: typedef boost::function<void(boost::array<T, U> & a)> t_SortFunction;
t_SortFunction m_SortFunction;
public: Sorter(t_SortFunction func) : m_SortFunction(func) {}
bool sort(boost::array<T, U> & a) { m_SortFunction(a); } };
template<typename T, std::size_t U> void quicksort(boost::array<T, U> & a) { }
int main(int argc, char* argv[]) {
Sorter shell(boost::bind(quicksort, _1));
return 0; }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

michi7x7 wrote:
Am 11.10.2010 01:59, schrieb Ryan McConnehey: Hi,
yes it is, but you need to pass the template-parameters:
Sorter<int, 8> shell(boost::bind(quicksort<int, 8>, _1));
or simply
Sorter<int, 8> shell(quicksort<int,8>);
Regards,
michi7x7 By binding to the exact template parameters it makes the Sorter not as flexible as I'm hoping. If I have two boost arrays defined like so.
boost::array<int, 100> base10power2; boost::array<int, 1000> base10power3; Is there a way to just bind the array type but not the size. This would let me call the same method with different size arrays. Sorter<int, ?> shell(boost::bind(quicksort<int, ?>, _1)); shell(base10power2); shell(base10power3); Ryan

Am 11.10.2010 21:46, schrieb Ryan McConnehey:
michi7x7 wrote:
Am 11.10.2010 01:59, schrieb Ryan McConnehey: Hi,
yes it is, but you need to pass the template-parameters:
Sorter<int, 8> shell(boost::bind(quicksort<int, 8>, _1));
or simply
Sorter<int, 8> shell(quicksort<int,8>);
Regards,
michi7x7 By binding to the exact template parameters it makes the Sorter not as flexible as I'm hoping. If I have two boost arrays defined like so.
boost::array<int, 100> base10power2; boost::array<int, 1000> base10power3;
Is there a way to just bind the array type but not the size. This would let me call the same method with different size arrays.
Hi, unfortunately not with boost::array, because the array-size is static. Use std::vector instead ;) Regards, michi7x7

On Mon, Oct 11, 2010 at 1:55 PM, michi7x7 <mailing-lists@michi7x7.de> wrote:
Am 11.10.2010 21:46, schrieb Ryan McConnehey:
michi7x7 wrote:
Am 11.10.2010 01:59, schrieb Ryan McConnehey: Hi,
yes it is, but you need to pass the template-parameters:
Sorter<int, 8> shell(boost::bind(quicksort<int, 8>, _1));
or simply
Sorter<int, 8> shell(quicksort<int,8>);
Regards,
michi7x7
By binding to the exact template parameters it makes the Sorter not as flexible as I'm hoping. If I have two boost arrays defined like so.
boost::array<int, 100> base10power2; boost::array<int, 1000> base10power3;
Is there a way to just bind the array type but not the size. This would let me call the same method with different size arrays.
Hi,
unfortunately not with boost::array, because the array-size is static. Use std::vector instead ;)
No, he can do it, but not with Boost.Bind that I know of, use Boost.Phoenix instead, it can do this easily (reference Boost.Phoenix.Function wrapper). Actually, he might be able to do it with Boost.Bind if he wraps it in a functor with an operator() that calls his template function...
participants (3)
-
michi7x7
-
OvermindDL1
-
Ryan McConnehey