當前位置: 首頁>>代碼示例>>C++>>正文


C++ dependent::size方法代碼示例

本文整理匯總了C++中dependent::size方法的典型用法代碼示例。如果您正苦於以下問題:C++ dependent::size方法的具體用法?C++ dependent::size怎麽用?C++ dependent::size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dependent的用法示例。


在下文中一共展示了dependent::size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: noContainer

// Check for loops that don't mention containers
void noContainer() {
  for (auto i = 0; i < v.size(); ++i) { }
  // CHECK: for (auto & elem : v) { }

  for (auto i = 0; i < v.size(); ++i) ;
  // CHECK: for (auto & elem : v) ;
}
開發者ID:aleguna,項目名稱:llvm-project,代碼行數:8,代碼來源:pseudoarray.cpp

示例2: noContainer

// Check for loops that don't mention containers.
void noContainer() {
  for (auto i = 0; i < v.size(); ++i) {
  }

  for (auto i = 0; i < v.size(); ++i)
    ;
}
開發者ID:urho3d,項目名稱:clang-tools-extra,代碼行數:8,代碼來源:modernize-loop-convert-basic.cpp

示例3: noContainer

// Check for loops that don't mention containers.
void noContainer() {
  for (auto I = 0; I < V.size(); ++I) {
  }

  for (auto I = 0; I < V.size(); ++I)
    ;
}
開發者ID:krzysztofjanski,項目名稱:clang-tools-extra,代碼行數:8,代碼來源:modernize-loop-convert-basic.cpp

示例4: memberFunctionCalled

// Checks to see that non-const member functions are not called on the container
// object.
// These could be conceivably allowed with a lower required confidence level.
void memberFunctionCalled() {
  for (int i = 0; i < v.size(); ++i) {
    sum += v[i];
    v.foo();
  }

  for (int i = 0; i < v.size(); ++i) {
    sum += v[i];
    dependent<int>::iterator it = v.begin();
  }
}
開發者ID:309972460,項目名稱:software,代碼行數:14,代碼來源:negative-pseudoarray-extra.cpp

示例5: increment

// Checks for invalid increment steps:
void increment() {
  for (int i = 0; i < v.size(); --i)
    sum += v[i];

  for (int i = 0; i < v.size(); i)
    sum += v[i];

  for (int i = 0; i < v.size();)
    sum += v[i];

  for (int i = 0; i < v.size(); i += 2)
    sum ++;
}
開發者ID:309972460,項目名稱:software,代碼行數:14,代碼來源:negative-pseudoarray.cpp

示例6: f

void f() {
  int Sum = 0;
  for (int I = 0, E = V.size(); I < E; ++I) {
    printf("Fibonacci number is %d\n", V[I]);
    Sum += V[I] + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Elem : V)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
  // CHECK-FIXES-NEXT: Sum += Elem + 2;

  for (int I = 0, E = V.size(); I < E; ++I) {
    printf("Fibonacci number is %d\n", V.at(I));
    Sum += V.at(I) + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Elem : V)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
  // CHECK-FIXES-NEXT: Sum += Elem + 2;

  for (int I = 0, E = Pv->size(); I < E; ++I) {
    printf("Fibonacci number is %d\n", Pv->at(I));
    Sum += Pv->at(I) + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Elem : *Pv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
  // CHECK-FIXES-NEXT: Sum += Elem + 2;

  // This test will fail if size() isn't called repeatedly, since it
  // returns unsigned int, and 0 is deduced to be signed int.
  // FIXME: Insert the necessary explicit conversion, or write out the types
  // explicitly.
  for (int I = 0; I < Pv->size(); ++I) {
    printf("Fibonacci number is %d\n", (*Pv).at(I));
    Sum += (*Pv)[I] + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Elem : *Pv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
  // CHECK-FIXES-NEXT: Sum += Elem + 2;

  for (int I = 0; I < Cv->size(); ++I) {
    printf("Fibonacci number is %d\n", Cv->at(I));
    Sum += Cv->at(I) + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Elem : *Cv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem);
  // CHECK-FIXES-NEXT: Sum += Elem + 2;
}
開發者ID:krzysztofjanski,項目名稱:clang-tools-extra,代碼行數:51,代碼來源:modernize-loop-convert-basic.cpp

示例7: f

void f() {
  int sum = 0;
  for (int i = 0, e = v.size(); i < e; ++i) {
    printf("Fibonacci number is %d\n", v[i]);
    sum += v[i] + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : v)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem);
  // CHECK-FIXES-NEXT: sum += elem + 2;

  for (int i = 0, e = v.size(); i < e; ++i) {
    printf("Fibonacci number is %d\n", v.at(i));
    sum += v.at(i) + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : v)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem);
  // CHECK-FIXES-NEXT: sum += elem + 2;

  for (int i = 0, e = pv->size(); i < e; ++i) {
    printf("Fibonacci number is %d\n", pv->at(i));
    sum += pv->at(i) + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : *pv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem);
  // CHECK-FIXES-NEXT: sum += elem + 2;

  // This test will fail if size() isn't called repeatedly, since it
  // returns unsigned int, and 0 is deduced to be signed int.
  // FIXME: Insert the necessary explicit conversion, or write out the types
  // explicitly.
  for (int i = 0; i < pv->size(); ++i) {
    printf("Fibonacci number is %d\n", (*pv).at(i));
    sum += (*pv)[i] + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : *pv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem);
  // CHECK-FIXES-NEXT: sum += elem + 2;

  for (int i = 0; i < cv->size(); ++i) {
    printf("Fibonacci number is %d\n", cv->at(i));
    sum += cv->at(i) + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : *cv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem);
  // CHECK-FIXES-NEXT: sum += elem + 2;
}
開發者ID:nick-schultz,項目名稱:clang-tools-extra,代碼行數:51,代碼來源:modernize-loop-convert-basic.cpp

示例8: mixedVariables

// Checks for incorrect loop variables.
void mixedVariables() {
  int badIndex;
  for (int i = 0; badIndex < v.size(); ++i)
    sum += v[i];

  for (int i = 0; i < v.size(); ++badIndex)
    sum += v[i];

  for (int i = 0; badIndex < v.size(); ++badIndex)
    sum += v[i];

  for (int i = 0; badIndex < v.size(); ++badIndex)
    sum += v[badIndex];
}
開發者ID:309972460,項目名稱:software,代碼行數:15,代碼來源:negative-pseudoarray.cpp

示例9: indexStartAndEnd

// Checks for the index start and end:
void indexStartAndEnd() {
  for (int i = 0; i < v.size() + 1; ++i)
    sum += v[i];

  for (int i = 0; i < v.size() - 1; ++i)
    sum += v[i];

  for (int i = 1; i < v.size(); ++i)
    sum += v[i];

  for (int i = 1; i < v.size(); ++i)
    sum += v[i];

  for (int i = 0; ; ++i)
    sum += (*pv)[i];
}
開發者ID:309972460,項目名稱:software,代碼行數:17,代碼來源:negative-pseudoarray.cpp

示例10: multipleArrays

// Checks for an array indexed in addition to the container.
void multipleArrays() {
  int badArr[N];

  for (int i = 0; i < v.size(); ++i)
    sum += v[i] + badArr[i];

  for (int i = 0; i < v.size(); ++i)
    sum += badArr[i];

  for (int i = 0; i < v.size(); ++i) {
    int k = badArr[i];
    sum += k + 2;
  }

  for (int i = 0; i < v.size(); ++i) {
    int k = badArr[i];
    sum += v[i] + k;
  }
}
開發者ID:309972460,項目名稱:software,代碼行數:20,代碼來源:negative-pseudoarray.cpp

示例11: multipleContainers

// Checks for multiple containers being indexed container.
void multipleContainers() {
  dependent<int> badArr;

  for (int i = 0; i < v.size(); ++i)
    sum += v[i] + badArr[i];

  for (int i = 0; i < v.size(); ++i)
    sum += badArr[i];

  for (int i = 0; i < v.size(); ++i) {
    int k = badArr[i];
    sum += k + 2;
  }

  for (int i = 0; i < v.size(); ++i) {
    int k = badArr[i];
    sum += v[i] + k;
  }
}
開發者ID:309972460,項目名稱:software,代碼行數:20,代碼來源:negative-pseudoarray.cpp

示例12: constness

// Ensure that 'const auto &' is used with containers of non-trivial types.
void constness() {
  int Sum = 0;
  for (int I = 0, E = Constv.size(); I < E; ++I) {
    printf("Fibonacci number is %d\n", Constv[I].X);
    Sum += Constv[I].X + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (const auto & Elem : Constv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;

  for (int I = 0, E = Constv.size(); I < E; ++I) {
    printf("Fibonacci number is %d\n", Constv.at(I).X);
    Sum += Constv.at(I).X + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (const auto & Elem : Constv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;

  for (int I = 0, E = Pconstv->size(); I < E; ++I) {
    printf("Fibonacci number is %d\n", Pconstv->at(I).X);
    Sum += Pconstv->at(I).X + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (const auto & Elem : *Pconstv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;

  // This test will fail if size() isn't called repeatedly, since it
  // returns unsigned int, and 0 is deduced to be signed int.
  // FIXME: Insert the necessary explicit conversion, or write out the types
  // explicitly.
  for (int I = 0; I < Pconstv->size(); ++I) {
    printf("Fibonacci number is %d\n", (*Pconstv).at(I).X);
    Sum += (*Pconstv)[I].X + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (const auto & Elem : *Pconstv)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X);
  // CHECK-FIXES-NEXT: Sum += Elem.X + 2;
}
開發者ID:krzysztofjanski,項目名稱:clang-tools-extra,代碼行數:43,代碼來源:modernize-loop-convert-basic.cpp

示例13: constRef

void constRef(const dependent<int>& ConstVRef) {
  int sum = 0;
  // FIXME: This does not work with size_t (probably due to the implementation
  // of dependent); make dependent work exactly like a std container type.
  for (int i = 0; i < ConstVRef.size(); ++i) {
    sum += ConstVRef[i];
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Elem : ConstVRef)
  // CHECK-FIXES-NEXT: sum += Elem;

  for (auto I = ConstVRef.begin(), E = ConstVRef.end(); I != E; ++I) {
    sum += *I;
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Elem : ConstVRef)
  // CHECK-FIXES-NEXT: sum += Elem;
}
開發者ID:krzysztofjanski,項目名稱:clang-tools-extra,代碼行數:18,代碼來源:modernize-loop-convert-basic.cpp

示例14: loops

  void loops() {
    for (int I = 0; I < N; ++I) {
      printf("%d\n", Ints[I]);
    }
    // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
    // CHECK-FIXES: for (int Int : Ints)
    // CHECK-FIXES-NEXT: printf("%d\n", Int);

    for (int I = 0; I < N; ++I) {
      printf("%d\n", Ints_[I]);
    }
    // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
    // CHECK-FIXES: for (int Int : Ints_)
    // CHECK-FIXES-NEXT: printf("%d\n", Int);

    for (int I = 0; I < DInts.size(); ++I) {
      printf("%d\n", DInts[I]);
    }
    // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
    // CHECK-FIXES: for (int DInt : DInts)
    // CHECK-FIXES-NEXT: printf("%d\n", DInt);
  }
開發者ID:berenm,項目名稱:swang,代碼行數:22,代碼來源:modernize-loop-convert-extra.cpp

示例15: aliasing

void aliasing() {
  // If the loop container is only used for a declaration of a temporary
  // variable to hold each element, we can name the new variable for the
  // converted range-based loop as the temporary variable's name.

  // In the following case, "t" is used as a temporary variable to hold each
  // element, and thus we consider the name "t" aliased to the loop.
  // The extra blank braces are left as a placeholder for after the variable
  // declaration is deleted.
  for (int i = 0; i < N; ++i) {
    Val &t = Arr[i];
    {}
    int y = t.x;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & t : Arr)
  // CHECK-FIXES-NOT: Val &{{[a-z_]+}} =
  // CHECK-FIXES: {}
  // CHECK-FIXES-NEXT: int y = t.x;

  // The container was not only used to initialize a temporary loop variable for
  // the container's elements, so we do not alias the new loop variable.
  for (int i = 0; i < N; ++i) {
    Val &t = Arr[i];
    int y = t.x;
    int z = Arr[i].x + t.x;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : Arr)
  // CHECK-FIXES-NEXT: Val &t = elem;
  // CHECK-FIXES-NEXT: int y = t.x;
  // CHECK-FIXES-NEXT: int z = elem.x + t.x;

  for (int i = 0; i < N; ++i) {
    Val t = Arr[i];
    int y = t.x;
    int z = Arr[i].x + t.x;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : Arr)
  // CHECK-FIXES-NEXT: Val t = elem;
  // CHECK-FIXES-NEXT: int y = t.x;
  // CHECK-FIXES-NEXT: int z = elem.x + t.x;

  // The same for pseudo-arrays like std::vector<T> (or here dependent<Val>)
  // which provide a subscript operator[].
  for (int i = 0; i < v.size(); ++i) {
    Val &t = v[i];
    {}
    int y = t.x;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & t : v)
  // CHECK-FIXES: {}
  // CHECK-FIXES-NEXT: int y = t.x;

  // The same with a call to at()
  for (int i = 0; i < pv->size(); ++i) {
    Val &t = pv->at(i);
    {}
    int y = t.x;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & t : *pv)
  // CHECK-FIXES: {}
  // CHECK-FIXES-NEXT: int y = t.x;

  for (int i = 0; i < N; ++i) {
    Val &t = func(Arr[i]);
    int y = t.x;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & elem : Arr)
  // CHECK-FIXES-NEXT: Val &t = func(elem);
  // CHECK-FIXES-NEXT: int y = t.x;

  int IntArr[N];
  for (unsigned i = 0; i < N; ++i) {
    if (int alias = IntArr[i]) {
      sideEffect(alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto alias : IntArr)
  // CHECK-FIXES-NEXT: if (alias)

  for (unsigned i = 0; i < N; ++i) {
    while (int alias = IntArr[i]) {
      sideEffect(alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto alias : IntArr)
  // CHECK-FIXES-NEXT: while (alias)

  for (unsigned i = 0; i < N; ++i) {
    switch (int alias = IntArr[i]) {
    default:
      sideEffect(alias);
    }
//.........這裏部分代碼省略.........
開發者ID:urho3d,項目名稱:clang-tools-extra,代碼行數:101,代碼來源:modernize-loop-convert-extra.cpp


注:本文中的dependent::size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。