int main () { constexpr S a {}; constexpr int i = a.foo (0); constexpr int j = a.bar (0); static_assert (i == j, "Ouch"); }
void refs_and_vals() { // The following tests check that the transform correctly preserves the // reference or value qualifiers of the aliased variable. That is, if the // variable was declared as a value, the loop variable will be declared as a // value and vice versa for references. S s; const S s_const = s; for (S::const_iterator it = s_const.begin(); it != s_const.end(); ++it) { MutableVal alias = *it; {} alias.x = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (auto alias : s_const) // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} = // CHECK-FIXES: {} // CHECK-FIXES-NEXT: alias.x = 0; for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { MutableVal alias = *it; {} alias.x = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (auto alias : s) // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} = // CHECK-FIXES: {} // CHECK-FIXES-NEXT: alias.x = 0; for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { MutableVal &alias = *it; {} alias.x = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (auto & alias : s) // CHECK-FIXES-NOT: MutableVal &{{[a-z_]+}} = // CHECK-FIXES: {} // CHECK-FIXES-NEXT: alias.x = 0; dependent<int> dep, other; for (dependent<int>::iterator it = dep.begin(), e = dep.end(); it != e; ++it) { printf("%d\n", *it); const int& idx = other[0]; unsigned othersize = other.size(); } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (auto & elem : dep) // CHECK-FIXES-NEXT: printf("%d\n", elem); // CHECK-FIXES-NEXT: const int& idx = other[0]; // CHECK-FIXES-NEXT: unsigned othersize = other.size(); for (int i = 0, e = dep.size(); i != e; ++i) { int idx = other.at(i); } }
void refs_and_vals() { // The following tests check that the transform correctly preserves the // reference or value qualifiers of the aliased variable. That is, if the // variable was declared as a value, the loop variable will be declared as a // value and vice versa for references. S Ss; const S S_const = Ss; for (S::const_iterator It = S_const.begin(); It != S_const.end(); ++It) { MutableVal Alias = *It; {} Alias.X = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (auto Alias : S_const) // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} = // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: Alias.X = 0; for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { MutableVal Alias = *It; {} Alias.X = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (auto Alias : Ss) // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} = // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: Alias.X = 0; for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { MutableVal &Alias = *It; {} Alias.X = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (auto & Alias : Ss) // CHECK-FIXES-NOT: MutableVal &{{[a-z_]+}} = // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: Alias.X = 0; dependent<int> Dep, Other; for (dependent<int>::iterator It = Dep.begin(), E = Dep.end(); It != E; ++It) { printf("%d\n", *It); const int& Idx = Other[0]; unsigned Othersize = Other.size(); } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-FIXES: for (int & It : Dep) // CHECK-FIXES-NEXT: printf("%d\n", It); // CHECK-FIXES-NEXT: const int& Idx = Other[0]; // CHECK-FIXES-NEXT: unsigned Othersize = Other.size(); for (int I = 0, E = Dep.size(); I != E; ++I) { int Idx = Other.at(I); } }
void multipleEnd() { for (S::iterator i = s.begin(); i != s.end(); ++i) MutableVal k = *i; for (T::iterator i = t.begin(); i != t.end(); ++i) int k = *i; for (U::iterator i = u.begin(); i != u.end(); ++i) Val k = *i; }
void example() { S s; s.func(); static_cast<const S&>(s).func(); static_cast<volatile S&>(s).func(); const S sc; sc.increment(); }
int main() { S s1; const S s2; volatile S s3; const volatile S s4; s1.foo(); s2.foo(); s3.foo(); s4.foo(); }
int operator()(Concept) { auto t = get_table<typename Concept::Table>(src->table()->type_info, src); if (!t) { std::cerr << "get concept " << typeid(Concept).name() << " table for type " << src->table()->type_info->name() << " failed when castting from " << typeid(S).name() << " to " << typeid(D).name() << std::endl; abort(); } *static_cast<typename Concept::Table *>(table) = *t; return 0; }
GvmResult(GvmCluster<S,V,K,FP> cluster) : space(cluster.clusters.space) { count = cluster.count; mass = cluster.m0; variance = cluster.var / mass; stdDeviation = FP(-1.0); key = cluster.getKey(); //space = cluster.clusters.space; point = space.newCopy(cluster.m1); space.scale(point, FP(1.0) / mass); }
// p is prefix for com files, i.e., "/tmp/sswat", which would result in com // files of "/tmp/sswat.kcuf-in" and "/tmp/sswat.kcuf-out". // KCUF(const char *p = 0) { if(p) { in.set(p); out.set(p); } in.cat("kcuf-in"); out.cat("kcuf-out"); fin = new File(in); fout = new File(out); }
int main() { static S x; static T y; V *p; x.foo(17); p = &x; p->foo(18); p = &y; p->foo(12); _PASS; }
int main( void ) { bare(); sv.smemb(); tv.tmemb(); _PASS; }
int main() { { typedef std::string S; const S s; assert(s.front() == 0); assert(false); } #if __cplusplus >= 201103L { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; const S s; assert(s.front() == 0); assert(false); } #endif }
void foo () { #pragma omp sections firstprivate(x) lastprivate(x) { x.test(); } }
int main() { { typedef std::string S; const S s; assert(s.front() == 0); assert(false); } #if TEST_STD_VER >= 11 { typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; const S s; assert(s.front() == 0); assert(false); } #endif }
std::string toString() { std::stringstream sb; char buffer[100]; sb << space.toString(point); // FIXME: use generic toString() method defined on the specific key type snprintf(buffer, 100, " count: %d variance: %3.3f mass: %3.3f key: %p", count, variance, mass, key); sb << buffer; return sb.str(); }
void refs_and_vals() { // The following tests check that the transform correctly preserves the // reference or value qualifiers of the aliased variable. That is, if the // variable was declared as a value, the loop variable will be declared as a // value and vice versa for references. S s; const S s_const = s; for (S::const_iterator it = s_const.begin(); it != s_const.end(); ++it) { MutableVal alias = *it; { } alias.x = 0; } // CHECK: for (auto alias : s_const) // CHECK-NOT: MutableVal {{[a-z_]+}} = // CHECK-NEXT: { } // CHECK-NEXT: alias.x = 0; for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { MutableVal alias = *it; { } alias.x = 0; } // CHECK: for (auto alias : s) // CHECK-NOT: MutableVal {{[a-z_]+}} = // CHECK-NEXT: { } // CHECK-NEXT: alias.x = 0; for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { MutableVal &alias = *it; { } alias.x = 0; } // CHECK: for (auto & alias : s) // CHECK-NOT: MutableVal &{{[a-z_]+}} = // CHECK-NEXT: { } // CHECK-NEXT: alias.x = 0; }
string_out_iterator& operator=(typename S::value_type v) { out->append(1, v); return *this; }
// PR c++/49290 // { dg-options -std=c++11 } typedef unsigned T; struct S { constexpr T foo (void); unsigned s1[16]; }; constexpr T S::foo () { return *(T *) (s1 + 10); } constexpr S s = { 0,1,2,3,4,5,6,7,8,9,10 }; #define SA(X) static_assert ((X), #X) SA(s.foo() == 10);
void operator()(int i) { if (keep[i]) keep[i] = !step.commit(I[i]); }
void operator()(int i) { if (i >= numberKeep) I[i] = numberDone + i; keep[i] = step.reserve(I[i]); }
inline int bbox(dim_t axis) const { return (int)last_.bbox(axis); }
// RUN: %clang_cc1 -std=c++1y -verify %s -fcxx-exceptions -triple=x86_64-linux-gnu struct S { // dummy ctor to make this a literal type constexpr S(int); S(); int arr[10]; constexpr int &get(int n) { return arr[n]; } constexpr const int &get(int n) const { return arr[n]; } }; S s = S(); const S &sr = s; static_assert(&s.get(4) - &sr.get(2) == 2, ""); // Compound-statements can be used in constexpr functions. constexpr int e() {{{{}} return 5; }} static_assert(e() == 5, ""); // Types can be defined in constexpr functions. constexpr int f() { enum E { e1, e2, e3 }; struct S { constexpr S(E e) : e(e) {} constexpr int get() { return e; } E e; };
void operator()(const T& model) const { slha_io->set_spectrum(model); }
// 2 defined before first use // NOTE: this is only needed in contexts that require a constant-expression struct S { constexpr int twice(); constexpr int t(); // { dg-message "used but never defined" } private: static constexpr int val = 7; // constexpr variable }; constexpr int S::twice() { return val + val; } constexpr S s = { }; int x1 = s.twice(); // ok int x2 = s.t(); // error: S::t() not defined constexpr int x2a = s.t(); // { dg-error "S::t" } error: S::t() not defined constexpr int ff(); // ok constexpr int gg(); // ok int x3 = ff(); // error: ff() not defined constexpr int x3a = ff(); // { dg-error "ff" } error: ff() not defined constexpr int ff() { return 1; // too late } constexpr int gg() { return 2; } int x4 = gg(); // ok
foo () { this_s.run(); }
int start() { int draws = 0; int algorithm_1_wins = 0; int algorithm_2_wins = 0; char enemy = root->get_enemy(root->player_to_move); for (int i = 1; i <= MATCHES; ++i) { auto current = root->clone(); if (i % 4 == 0 || i % 4 == 2) { current.player_to_move = current.get_enemy(current.player_to_move); } if (i % 4 == 0 || i % 4 == 3) { current.swap_players(); } if (VERBOSE) { cout << current << endl; } while (!current.is_terminal()) { auto &algorithm = (current.player_to_move == root->player_to_move) ? algorithm_1 : algorithm_2; if (VERBOSE) { cout << current.player_to_move << " " << algorithm << endl; } algorithm.reset(); Timer timer; timer.start(); auto copy = current.clone(); auto move = algorithm.get_move(©); if (VERBOSE) { cout << timer << endl; } current.make_move(move); if (VERBOSE) { cout << current << endl; } } cout << "Match " << i << ": "; if (current.is_winner(root->player_to_move)) { ++algorithm_1_wins; cout << root->player_to_move << " " << algorithm_1 << " won" << endl; } else if (current.is_winner(enemy)) { ++algorithm_2_wins; cout << enemy << " " << algorithm_2 << " won" << endl; } else { ++draws; cout << "draw" << endl; } cout << root->player_to_move << " " << algorithm_1 << " wins: " << algorithm_1_wins << endl; cout << enemy << " " << algorithm_2 << " wins: " << algorithm_2_wins << endl; cout << "Draws: " << draws << endl; double successes = algorithm_1_wins + 0.5 * draws; double ratio = successes / i; cout << "Ratio: " << ratio << endl; double lower = boost::math::binomial_distribution<>::find_lower_bound_on_p(i, successes, SIGNIFICANCE_LEVEL); double upper = boost::math::binomial_distribution<>::find_upper_bound_on_p(i, successes, SIGNIFICANCE_LEVEL); cout << "Lower confidence bound: " << lower << endl; cout << "Upper confidence bound: " << upper << endl; cout << endl; if (upper < 0.5 || lower > 0.5) { break; } } return draws; }