int main(int argc, char const *argv[])
{
	list_t *list = (list_t*)malloc(sizeof (list_t));
	init(list);

	//make a node
	add_at(list, (void*)2, 0);
	assert(list->head && list->tail);
	assert((int) get(list, 0) == 2);
	//do more adding
	int i = 3;
	for(; i < 15; ++i){
		add_front(list, (void*)i);
		assert(list->head && list->tail);
		assert((int) get(list, 0) == i);
	}
	assert((int) get(list, list->size - 1) == 2);
	assert((int) fold_left(list, add_list, (void*)0) == 104);
	assert((int) fold_left(list, add_list, (void*)0) == (int)fold_right(list, add_list, (void*)0));
	add_back(list, (void*)0);
	assert(list->tail->data == (void*)0);
	assert((int) get(list, list->size - 1) == 0);
	add_front(list, (void*)2);
	add_front(list, (void*)2);
	assert((int) fold_left(list, count_2, (void*)0) == 3);
	remove_data(list, (void*)2, is_2);
	return 0;
}
Beispiel #2
0
 std::vector<std::vector<T>> helper_carthesian_product_n_idxs
         (std::size_t power, const std::vector<T>& xs)
 {
     static_assert(std::is_same<T, std::size_t>::value,
         "T must be std::size_t");
     typedef std::vector<T> Vec;
     typedef std::vector<Vec> VecVec;
     if (power == 0)
         return VecVec();
     auto go = [](const Vec& elems, const VecVec& acc)
     {
         VecVec result;
         for (const T& x : elems)
         {
             for (const Vec& tail : acc)
             {
                 result.push_back(append(Vec(1, x), tail));
             }
         }
         return result;
     };
     return fold_right(go, VecVec(1), replicate(power, xs));
 }
Beispiel #3
0
IStaging::joint_pointer fold (const IStaging::joint_pointer& a_joint)
{
	return fold_right(fold_left(a_joint));
}