int main() { LazyConstruction<int> v1; v1.construct(1); assert(*v1 == 1); LazyConstruction<int> v1_1; // v1_1 = v1; // runtime error : v1_1 is not constructed yet. LazyConstruction<int> v1_2(v1); assert(*v1_2 == 1); /* ----------------------- */ LazyConstruction<std::string> v2; v2.construct("ss"); assert(*v2 == "ss"); *v2 += "s"; assert(*v2 == "sss"); const LazyConstruction<std::string> v2_1(v2); // v2_1.construct("sss"); // compile error : v2_1 is constant // *v2_1 += "s"; // compile error : *v2_1 is constant LazyConstruction<const std::string> v2_2; v2_2.construct("sss"); assert(*v2_2 == "sss"); // *v2_2 += "s"; // compile error : *v2_2 is constant LazyConstruction<const std::string> v2_3(v2_2); // v2_3 = v2_2; // compile error : *v2_3 is constant LazyConstruction<const std::string> v2_4(std::move(v2_2)); assert(*v2_4 == "sss"); /* ----------------------- */ LazyConstruction<NoCopyable> v3; v3.construct(3); assert(v3->i == 3); // LazyConstruction<NoCopyable> v3_1(v3); // compile error : can't copy construction LazyConstruction<NoCopyable> v3_1(std::move(v3)); assert(v3_1->i == 3); LazyConstruction<NoCopyable> v3_2; // v3_2 = v3_1; // compile error : can't copy assignment // v3_2 = std::move(v3_1); // runtime error : v3_2 is not constructed yet. /* ------------------------ */ Contain v4; auto v4_1 = v4; Contain v4_2; v4_2 = v4; return 0; }
bool edge_intersection (const Molecule &mol, int edge1_idx, int edge2_idx, Vec2f &p) { const Edge &edge1 = mol.getEdge(edge1_idx); const Edge &edge2 = mol.getEdge(edge2_idx); if (edge1.beg == edge2.beg || edge1.beg == edge2.end || edge1.end == edge2.beg || edge1.end == edge2.end) return false; Vec2f v1_1(mol.getAtomPos(edge1.beg).x, mol.getAtomPos(edge1.beg).y); Vec2f v1_2(mol.getAtomPos(edge1.end).x, mol.getAtomPos(edge1.end).y); Vec2f v2_1(mol.getAtomPos(edge2.beg).x, mol.getAtomPos(edge2.beg).y); Vec2f v2_2(mol.getAtomPos(edge2.end).x, mol.getAtomPos(edge2.end).y); return Vec2f::intersection(v1_1, v1_2, v2_1, v2_2, p); }
std::unique_ptr<WirelessProtocol> WirelessProtocol::chooseNodeProtocol(const Version& fwVersion) { if(fwVersion >= NodeFeatures::MIN_NODE_FW_PROTOCOL_1_5) { return v1_5(); } else if(fwVersion >= NodeFeatures::MIN_NODE_FW_PORTOCOL_1_4) { return v1_4(); } else if(fwVersion >= NodeFeatures::MIN_NODE_FW_PROTOCOL_1_2) { return v1_2(); } else if(fwVersion >= NodeFeatures::MIN_NODE_FW_PROTOCOL_1_1) { return v1_1(); } else { return v1_0(); } }