多重forループを書きやすくしたい

のでちょっと書いてみた。C++11限定でBoostが必要。
こんな風に使う。

#include <iostream>
#include "feux/multiple_for.hpp"

typedef std::pair<int,int> Range;

int main() {
    const Range range1 = std::make_pair(0,3);
    const Range range2 = std::make_pair(0,3);
    const Range range3 = std::make_pair(0,3);
    const Range range4 = std::make_pair(0,3);

    // 4重ループ
    feux::multiple_for(
            [](int i,int j,int k,int l){ printf("%d %d %d %d\n",i,j,k,l); },
            range1, range2, range3, range4);
    return 0;
}

16重まではイケるはず
まあお遊びみたいなものなので、使い勝手がいいかは知らない。
ヘッダはこちら

/*
 * 多重forループ文
 */
#pragma once
#include <algorithm>
#include <boost/mpl/int.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/preprocessor/arithmetic/dec.hpp>
    
namespace feux {
            
template<class Function,class HR, class ... Ranges>
struct multiple_for_holder {
    static void invoke(boost::mpl::int_<1>,const Function func,const HR hr) {
        for(int i=hr.first;i<hr.second;++i) func(i);
    }

#define GEN_FUNCTION(z,n,data) \
    static void invoke(boost::mpl::int_<n>,const Function func,const HR hr,const Ranges ... tr) { \
        auto curried = [func](const int i) { \
            return [i,func](BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(n),const int I)){ \
                func(i,BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(n),I)); \
            }; \
        }; \
        for(int i=hr.first;i<hr.second;++i) multiple_for(curried(i),tr...); \
    }
    BOOST_PP_REPEAT_FROM_TO(2,16,GEN_FUNCTION,data)
#undef GEN_FUNCTION
};

template<class Function,class HR, class ... TR>
void multiple_for(const Function func,const HR range, const TR ... ranges) {
    multiple_for_holder<Function,HR,TR...>::invoke(
        boost::mpl::int_<sizeof...(ranges)+1>(),func,range, ranges...);
}
};

本当はfunctorとrangeの引数の順番を逆にしたいのですがそれはまた今度で。
いろいろ試行錯誤しながらだったので、ムダもありそう。