Exemple #1
0
TEST(read, into_variadic)
{
  using tup = std::tuple<int, std::string>;

  auto stream = std::stringstream{"1 hello 2 my 3 friend 4 !!"};
  auto res = into_vector(read<int, std::string>(stream));
  EXPECT_EQ(res, (decltype(res) {
        tup(1, "hello"), tup(2, "my"), tup(3, "friend"), tup(4, "!!") }));
}
Exemple #2
0
TEST(product, product)
{
    using tup = std::tuple<int, int>;
    auto v1 = std::vector<int> { 1, 2 };
    auto v2 = std::vector<int> { 4, 5 };
    auto res = into_vector(product(v2), v1);
    EXPECT_EQ(res, (decltype(res) {
        tup(1, 4), tup(1, 5), tup(2, 4), tup(2, 5)
    }));
}
Exemple #3
0
TEST(product, generator)
{
    using tup = std::tuple<int, int>;
    auto v1 = std::vector<int> { 1, 2 };
    auto v2 = std::vector<int> { 4, 5 };

    auto res = into_vector(comp(take(1), product(v1, v2)));
    EXPECT_EQ(res, (decltype(res) {
        tup(1, 4), tup(1, 5), tup(2, 4), tup(2, 5)
    }));
}
Exemple #4
0
TEST(dedupe, variadic)
{
  using tup = std::tuple<int, char>;
  auto v = std::vector<int> { 1, 2, 1, 1, 1, 1, 1 };
  auto res = into_vector(comp(cycle(std::string("aabb")), dedupe), v);

  EXPECT_EQ(res, (decltype(res) {
        tup(1, 'a'),
        tup(2, 'a'),
        tup(1, 'b'),
        tup(1, 'a'),
        tup(1, 'b')
    }));
}
void test_perfect_forwarding() {
    {
        using Tup = std::tuple<>;
        Tup tup;
        Tup const& ctup = tup;
        assert(do_forwarding_test<>(tup));
        assert(do_forwarding_test<>(ctup));
    }
    {
        using Tup = std::tuple<int>;
        Tup tup(42);
        Tup const& ctup = tup;
        assert(do_forwarding_test<int&>(tup));
        assert(do_forwarding_test<int const&>(ctup));
        assert(do_forwarding_test<int&&>(std::move(tup)));
        assert(do_forwarding_test<int const&&>(std::move(ctup)));
    }
    {
        using Tup = std::tuple<int&, const char*, unsigned&&>;
        int x = 42;
        unsigned y = 101;
        Tup tup(x, "hello world", std::move(y));
        Tup const& ctup = tup;
        assert((do_forwarding_test<int&, const char*&, unsigned&>(tup)));
        assert((do_forwarding_test<int&, const char* const&, unsigned &>(ctup)));
        assert((do_forwarding_test<int&, const char*&&, unsigned&&>(std::move(tup))));
        assert((do_forwarding_test<int&, const char* const&&, unsigned &&>(std::move(ctup))));
    }
    // test with pair<T, U>
    {
        using Tup = std::pair<int&, const char*>;
        int x = 42;
        Tup tup(x, "hello world");
        Tup const& ctup = tup;
        assert((do_forwarding_test<int&, const char*&>(tup)));
        assert((do_forwarding_test<int&, const char* const&>(ctup)));
        assert((do_forwarding_test<int&, const char*&&>(std::move(tup))));
        assert((do_forwarding_test<int&, const char* const&&>(std::move(ctup))));
    }
    // test with array<T, I>
    {
        using Tup = std::array<int, 3>;
        Tup tup = {42, 101, -1};
        Tup const& ctup = tup;
        assert((do_forwarding_test<int&, int&, int&>(tup)));
        assert((do_forwarding_test<int const&, int const&, int const&>(ctup)));
        assert((do_forwarding_test<int&&, int&&, int&&>(std::move(tup))));
        assert((do_forwarding_test<int const&&, int const&&, int const&&>(std::move(ctup))));
    }
}
int main() {
    std::tuple<char Foo::*, short Foo::*, int Foo::*> tup(&Foo::a, &Foo::b, &Foo::c);

    Foo foo;

    Widget<decltype(tup)>::call(pp, &foo, tup);
}
Exemple #7
0
void grouping::slide_notify()
{
	LOG_METHOD_TRACE;
	std::vector<boost::any> data(aggr_specs.size()/* + grp_attrs.size() */);

	unsigned int pos = 0;

	if (slide_len > 0)
	{
		// we are called from a slide notifier:
		// in this case we publish the aggregates of all groups
		for (hash_table::iterator it = htable.begin(); it != htable.end(); it++)
		{
			aggr_list_ptr aggregates = it->second;
			pos = 0;
			for (unsigned int i = 0; i < aggr_specs.size(); i++)
				data[pos++] = (*aggregates)[i].get_value();

			tuple_ptr tup (new tuple(data));
			publish_new(tup);
		}
	}
	else
	{
		// otherwise, we publish only the current group
		// aggregate values
		for (unsigned int i = 0; i < aggr_specs.size(); i++)
		{
//			boost::any v = (*current_group)[i].get_value();
//
//			std::cout << "aggr #" << i << ": " << v
//			<< " -- " << aggr_specs[i].attr_type
//			<< "(" << column_info::IntType << ")" << std::endl;

			data[pos++] = (*current_group)[i].get_value();
		}

		// group values
//		for (unsigned int i = 0; i < grp_attrs.size(); i++) {
//			data[pos++] = grp_values[i];
//		}

		tuple_ptr tup (new tuple(data));
		// LOG_INFO("grouping::publish: " << tup);
		publish_new(tup);
	}
}
Exemple #8
0
int main (int argc, char *argv[]) 
{
  std::tuple<int,char,std::string> tup( 4, 'c', std::string( "Hello World" ) );
  std::cout << std::get<0>(tup) << std::endl;
  std::cout << std::get<1>(tup) << std::endl;
  std::cout << std::get<2>(tup) << std::endl;

  return 0;
}
Exemple #9
0
int main()
{
	std::tuple<char, int, std::string> tup('4', 2, "asdf");
	auto result = invert(tup);
	std::cout << std::get<0>(result) << ' ' << std::get<1>(result) << ' ' << std::get<2>(result) << '\n';
    
    std::array<int, 7> arr = {{0,1,2,3,4,5,6}};
    auto result2 = invert(arr);
    std::cout << std::get<0>(result2) << "..." << std::get<6>(result2) << '\n';
}
Exemple #10
0
TEST(product, variadic)
{
    using tup = std::tuple<int, int, char>;
    auto v1 = std::vector<int> { 1, 2 };
    auto v2 = std::vector<int> { 4, 5 };
    auto v3 = std::vector<char> { 'a', 'b' };

    auto res = into_vector(product(v2, v3), v1);
    EXPECT_EQ(res, (decltype(res) {
        tup(1, 4, 'a'), tup(1, 4, 'b'), tup(1, 5, 'a'), tup(1, 5, 'b'),
            tup(2, 4, 'a'), tup(2, 4, 'b'), tup(2, 5, 'a'), tup(2, 5, 'b')
    }));
}
Exemple #11
0
PyObjectHandle LuaToPythonConverter::convertToTuple(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // Must convert to a Python tuple.
    PyObjectHandle tup(PySequence_Tuple(ref->obj.get()));
    checkPythonError(tup, L, "cannot convert to tuple");
    return tup;
  }

  return convertTupleFromTable(L, index, false);
}
Exemple #12
0
// Convert (Python) list to (C++) list.
template<typename T, int dim> boost::array<T, dim> pytuple2cpparr(PyObject* obj)
{
  unsigned int i;
  boost::array<T, dim> arr;
  boost::python::tuple tup(boost::python::borrowed(obj));
  unsigned int tuplen = extract<int>(tup.attr("__len__")());
  for(i=0; i<tuplen; i++)
    {
      T tupelem = extract<T>(tup[i]);
      arr[i] = tupelem;
    }  
  return arr;
}
PyObject* conf2dict(const Config *conf)
{
    if(!conf)
        return NULL;
    PyRef<> list(PyList_New(0));

    for(Config::const_iterator it=conf->begin(), end=conf->end();
        it!=end; ++it)
    {
        PyRef<> val(boost::apply_visitor(confval(), it->second));
        PyRef<> tup(Py_BuildValue("sO", it->first.c_str(), val.py()));
        if(PyList_Append(list.py(), tup.py()))
            throw std::runtime_error("Failed to insert into dictionary from conf2dict");
    }

    return list.releasePy();
}
Exemple #14
0
void grouping::slide_notify_remove()
{
	std::vector<boost::any> data(aggr_specs.size());

	LOG_TRACE("begin grouping::slide_notify_remove");
	// TODO: Statistik-Hook?
	unsigned int pos = 0;

	// aggregate values */
	for (unsigned int i = 0; i < aggr_specs.size(); i++)
	{
		data[pos++] = (*current_group)[i].get_value();
	}

	tuple_ptr tup (new tuple(data));
	// LOG_INFO("grouping::remove: " << tup);
	publish_outdated(tup);

	LOG_TRACE("end grouping::slide_notify");
}
Exemple #15
0
void f(const Args&... args) {
    std::tuple<Args...> tup(args...);
}
Exemple #16
0
void tuple_example() {
    boost::tuple<int, int, std::string> tup(1, 2, "Meow");
    assert(boost::get<0>(tup) == 1);
    assert(boost::get<2>(tup) == "Meow");
}
Exemple #17
0
void fusion_tuple_example() {
    boost::fusion::vector<int, int, std::string> tup(1, 2, "Meow");
    assert(boost::fusion::at_c<0>(tup) == 1);
    assert(boost::fusion::at_c<2>(tup) == "Meow");
}
Exemple #18
0
void replace(PPOpIn arg)
{
    xptr node, tmp_node, attr_node;
    schema_node_xptr scm_node;
    xqp_tuple t(arg.ts);

    xptr_sequence arg1seq;        // Indirection of nodes which are going to be replaced
    xptr_sequence arg1seq_tmp;    // Nodes which are going to be replaced
    xptr_sequence arg2seq;        // Nodes to replace with (both persistent and temp)

    /* Persistent nodes to replace with (+ theirs position in arg2seq) */
    descript_sequence arg3seq(2);

    upd_ns_map* ins_swiz = NULL;
    bool is_node_updated = true;

    /*
     * Fill up sequences with nodes to update and update with,
     * child (arg) returns the following sequence of items:
     * 1. node to be replaced (1)
     * 2. nodes to replace with (2)
     * 3. special tuple which contains separator value (3)
     */
    arg.op->next(t);

    while (!t.is_eos())
    {
        if (t.cells[0].is_node())
        {
            node = t.cells[0].get_node();
            CHECKP(node);
            /*
             * In (1) case node must be persistent (is_node_updated is true)
             * In (2) case it can be temporary
             * In both cases document nodes are not allowed
             */
            if ((!is_node_updated || is_node_persistent(node)) && !is_node_document(node))
            {
                xptr indir = nodeGetIndirection(node);

                if (is_node_updated)
                {
                    /* Case (1) - fill up sequence with nodes to be replaced */
                    is_node_updated=false;
                    /* Next nodes from arg are case (2) nodes, so we can use shared lock */
                    local_lock_mrg->lock(lm_s);
                    arg1seq.add(indir);
                    arg1seq_tmp.add(node);
                }
                else
                {
                    /* Case (2) - fill up sequence with nodes to replace with */
                    if (is_node_persistent(node))
                    {
                        xqp_tuple tup(2);
                        tup.copy(tuple_cell::node(node),tuple_cell((int64_t)(arg2seq.size())));
                        arg3seq.add(tup);
                    }
                    arg2seq.add(indir);
                }
            }
#ifndef IGNORE_UPDATE_ERRORS
            else
            {
                throw USER_EXCEPTION(SE2020);
            }
#endif
        }
        else
        {
            /* Must be separator in this case (3) */
            if (t.cells[0].get_atomic_type() == se_separator)
            {
                arg2seq.add(XNULL);
                is_node_updated=true;
                /* Next nodes from arg are case (1) node, so we can use shared lock */
                local_lock_mrg->lock(lm_x);
            }
#ifndef IGNORE_UPDATE_ERRORS
            else throw USER_EXCEPTION(SE2021);
#endif
        }

        arg.op->next(t);
    }

    /* Nothing to do in this case */
    if (arg1seq.size()<=0) return;

    /* Checking authorization */
    if (is_auth_check_needed(REPLACE_STATEMENT))
        auth_for_update(&arg1seq, REPLACE_STATEMENT, false);

    /* Find all common nodes in agr3seq (nodes to replace with) and
     * arg1seq_tmp (nodes to be replaced). Make a copy of all such nodes. */
    arg1seq_tmp.sort();
    arg3seq.sort();
    descript_sequence::iterator it3 = arg3seq.begin();
    xptr_sequence::iterator     it1 = arg1seq_tmp.begin();

    while(it3 != arg3seq.end() && it1 != arg1seq_tmp.end())
    {
        switch(nid_cmp_effective((*it3).cells[0].get_node(), *it1))
        {
        case 0: case -2:
            {
                node = copy_to_temp((*it3).cells[0].get_node());
                xptr indir=nodeGetIndirection(node);
                arg2seq.set(indir,(*it3).cells[1].get_xs_integer());
                ++it3;
            }
            break;
        case 1:
            ++it1;
            break;
        case 2:
            ++it1;
            break;
        case -1:
            ++it3;
            break;
        }
    }
#ifdef SE_ENABLE_TRIGGERS
    apply_per_statement_triggers(&arg1seq, false, NULL, false, TRIGGER_BEFORE, TRIGGER_REPLACE_EVENT);
#endif

    arg3seq.clear();
    xptr_sequence::iterator it  = arg1seq.begin();
    xptr_sequence::iterator sit = arg2seq.begin();
    int ctr=0;
    do
    {
        xqp_tuple tup(2);
        /* arg3seq will contain pairs: node -> int, namely
        * node to be replaced -> place in sequence of nodes to replace with */
        tup.copy(tuple_cell::node(indirectionDereferenceCP(*it)),tuple_cell((int64_t)ctr));
        arg3seq.add(tup);
        /* XNULL separates nodes in arg2seq (nodes replace with) per each
        * node in arg1seq (nodes to be replaced) */
        while(*sit!=XNULL)
        {
            sit++;
            ctr++;
        }
        sit++;
        ctr++;
        it++;
    } while (it != arg1seq.end());

    arg3seq.sort();
    it3=arg3seq.begin();
    descript_sequence arg4seq(2);
    do
    {
        node = (*it3).cells[0].get_node();
        xqp_tuple t = (*it3);
        t.cells[0].set_safenode(node);
        ++it3;
        arg4seq.add(t);

    } while (it3!=arg3seq.end());

    /* Deleting, inserting new nodes */
    it3 = arg4seq.end();
    do
    {
        --it3;
        node = (*it3).cells[0].get_safenode();
        int pos = (*it3).cells[1].get_xs_integer();
        sit = arg2seq.begin() + pos;
        CHECKP(node);
        xptr leftn   = nodeGetLeftSibling(node);
        xptr rightn  = nodeGetRightSibling(node);
        xptr par_ind = nodeGetParentIndirection(node);
        bool a_m = is_node_attribute(node);
        bool d_m = a_m || is_node_text(node);

#ifdef SE_ENABLE_TRIGGERS
        scm_node = getSchemaPointer(node);
        tmp_node = prepare_old_node(node, scm_node, TRIGGER_REPLACE_EVENT);

        /* Before-for-each-node triggers (cycle for all inserted nodes) */
        xptr_sequence::iterator tr_it = sit;
        while(*tr_it != XNULL)
        {
            if(apply_per_node_triggers(indirectionDereferenceCP(*tr_it),
                                       node,
                                       indirectionDereferenceCP(par_ind),
                                       scm_node,
                                       TRIGGER_BEFORE,
                                       TRIGGER_REPLACE_EVENT) == XNULL)
            {
                goto next_replacement;
            }
            tr_it++;
        }
#endif /* SE_ENABLE_TRIGGERS */

        //pre_deletion
        if (d_m)
        {
            delete_node(node, &delete_node_context);
        }
        //1.inserting attributes from sequence
        while(*sit != XNULL)
        {
            xptr node_child = indirectionDereferenceCP(*sit);
            CHECKP(node_child);
            if (is_node_attribute(node_child))
            {
                attr_node = deep_copy_node(XNULL, XNULL, indirectionDereferenceCP(par_ind), node_child, is_node_persistent(node_child) ? NULL : &ins_swiz, true);
#ifdef SE_ENABLE_TRIGGERS
                apply_per_node_triggers(attr_node, tmp_node, indirectionDereferenceCP(par_ind), scm_node, TRIGGER_AFTER, TRIGGER_REPLACE_EVENT);
#endif
            }
            sit++;
        }
        //2. finding place of insertion
        if (a_m)
        {
            node = getFirstChildNode(indirectionDereferenceCP(par_ind));
            if (node != XNULL)
            {
                CHECKP(node);
                if (is_node_element(node))
                {
                    rightn=node;
                    node=XNULL;
                }
                else
                {
                    rightn=XNULL;
                }
            }
        }
        else
        {
            if (d_m)
            {
                if (rightn==XNULL)
                    node=leftn;
                else
                    node=XNULL;
            }
        }
        //3.main insert cycle
        sit = arg2seq.begin() + pos;
        while(*sit != XNULL)
        {
            xptr node_child = indirectionDereferenceCP(*sit);
            CHECKP(node_child);
            if (!is_node_attribute(node_child))
            {
                node = deep_copy_node(node, rightn, indirectionDereferenceCP(par_ind), node_child, is_node_persistent(node_child) ? NULL : &ins_swiz, true);
#ifdef SE_ENABLE_TRIGGERS
                apply_per_node_triggers(node, tmp_node, indirectionDereferenceCP(par_ind), scm_node, TRIGGER_AFTER, TRIGGER_REPLACE_EVENT);
#endif
            }
            sit++;
        }
        //post_deletion
        if (!d_m)
        {
            xptr del_node = (*it3).cells[0].get_safenode();
            delete_node(del_node, &delete_node_context);
        }
next_replacement:;
    }
    while (it3 != arg4seq.begin());

    if (ins_swiz != NULL)
    {
        delete ins_swiz;
    }
#ifdef SE_ENABLE_FTSEARCH
    execute_modifications();
#endif
#ifdef SE_ENABLE_TRIGGERS
    apply_per_statement_triggers(NULL, false, NULL, false, TRIGGER_AFTER, TRIGGER_REPLACE_EVENT);
#endif
}
Exemple #19
0
int main()
{
	std::tuple<char, int, std::string> tup('4', 2, "asdf");
	auto result = invert(tup);
	std::cout << std::get<0>(result) << ' ' << std::get<1>(result) << ' ' << std::get<2>(result);
}
Exemple #20
0
RES Camera::_get_gizmo_geometry() const {


	Ref<SurfaceTool> surface_tool( memnew( SurfaceTool ));

	Ref<FixedMaterial> mat( memnew( FixedMaterial ));

	mat->set_parameter( FixedMaterial::PARAM_DIFFUSE,Color(1.0,0.5,1.0,0.5) );
	mat->set_line_width(4);
	mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
	mat->set_flag(Material::FLAG_UNSHADED,true);
	//mat->set_hint(Material::HINT_NO_DEPTH_DRAW,true);

	surface_tool->begin(Mesh::PRIMITIVE_LINES);
	surface_tool->set_material(mat);

	switch(mode) {

		case PROJECTION_PERSPECTIVE: {



			Vector3 side=Vector3( Math::sin(Math::deg2rad(fov)), 0, -Math::cos(Math::deg2rad(fov)) );
			Vector3 nside=side;
			nside.x=-nside.x;
			Vector3 up=Vector3(0,side.x,0);


#define ADD_TRIANGLE( m_a, m_b, m_c)\
{\
	surface_tool->add_vertex(m_a);\
	surface_tool->add_vertex(m_b);\
	surface_tool->add_vertex(m_b);\
	surface_tool->add_vertex(m_c);\
	surface_tool->add_vertex(m_c);\
	surface_tool->add_vertex(m_a);\
}

			ADD_TRIANGLE( Vector3(), side+up, side-up );
			ADD_TRIANGLE( Vector3(), nside+up, nside-up );
			ADD_TRIANGLE( Vector3(), side+up, nside+up );
			ADD_TRIANGLE( Vector3(), side-up, nside-up );

			side.x*=0.25;
			nside.x*=0.25;
			Vector3 tup( 0, up.y*3/2,side.z);
			ADD_TRIANGLE( tup, side+up, nside+up );

		} break;
		case PROJECTION_ORTHOGONAL: {

#define ADD_QUAD( m_a, m_b, m_c, m_d)\
{\
	surface_tool->add_vertex(m_a);\
	surface_tool->add_vertex(m_b);\
	surface_tool->add_vertex(m_b);\
	surface_tool->add_vertex(m_c);\
	surface_tool->add_vertex(m_c);\
	surface_tool->add_vertex(m_d);\
	surface_tool->add_vertex(m_d);\
	surface_tool->add_vertex(m_a);\
}

			float hsize=size*0.5;
			Vector3 right(hsize,0,0);
			Vector3 up(0,hsize,0);
			Vector3 back(0,0,-1.0);
			Vector3 front(0,0,0);

			ADD_QUAD( -up-right,-up+right,up+right,up-right);
			ADD_QUAD( -up-right+back,-up+right+back,up+right+back,up-right+back);
			ADD_QUAD( up+right,up+right+back,up-right+back,up-right);
			ADD_QUAD( -up+right,-up+right+back,-up-right+back,-up-right);

			right.x*=0.25;
			Vector3 tup( 0, up.y*3/2,back.z );
			ADD_TRIANGLE( tup, right+up+back, -right+up+back );

		} break;

	}

	return surface_tool->commit();

}
Exemple #21
0
/* setjmp buffer used for internal VM errors */

static jmp_buf jbError;

#ifdef DEBUGVM
  #define tup(a,b,c) {a, b, c}
#else
  #define tup(a,b,c) {a, b}
#endif

/* opproc - table describing all of the available opcodes */

static struct _opproc opproc[]=
{
  tup(op_add,       QOP_ADD,        "ADD"), /* this entry duplicated to fill zeroth position in table */
  tup(op_add,       QOP_ADD,        "ADD"),
  tup(op_subtract,  QOP_SUBTRACT,   "SUBTRACT"),
  tup(op_multiply,  QOP_MULTIPLY,   "MULTIPLY"),
  tup(op_divide,    QOP_DIVIDE,     "DIVIDE"),
  tup(op_mod,       QOP_MODULUS,    "MOD"),

  tup(op_logical,   QOP_LE,         "LE"),
  tup(op_logical,   QOP_LT,         "LT"),
  tup(op_logical,   QOP_EQ,         "EQ"),
  tup(op_logical,   QOP_NE,         "NE"),
  tup(op_logical,   QOP_GE,         "GE"),
  tup(op_logical,   QOP_GT,         "GT"),
  tup(op_logical,   QOP_LOR,        "LOR"),
  tup(op_logical,   QOP_LAND,       "LAND"),