+/** Generate all bounded combinatorial partitions of an integer n with exactly
+ * m parts (not including zero parts) in non-decreasing order.
+ */
+class partition_generator : public basic_partition_generator {
+private:
+ mutable std::vector<unsigned> partition; // current partition
+ mutable bool current_updated; // whether partition vector has been updated
+public:
+ partition_generator(unsigned n_, unsigned m_)
+ : basic_partition_generator(n_, m_), partition(m_), current_updated(false)
+ { }
+ // returns current partition in non-decreasing order, padded with zeros
+ const std::vector<unsigned>& get() const
+ {
+ if (!current_updated) {
+ for (unsigned i = 0; i < mpgen.m; ++i)
+ partition[i] = mpgen.x[i + 1];
+ }
+ return partition;
+ }
+ bool next()
+ {
+ current_updated = false;
+ return mpgen.next_partition();
+ }
+};
+