本文整理汇总了C++中std::array::size方法的典型用法代码示例。如果您正苦于以下问题:C++ array::size方法的具体用法?C++ array::size怎么用?C++ array::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::array
的用法示例。
在下文中一共展示了array::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawStartUp
void Monitor::drawStartUp() {
const int MID_X = (sim::MONITOR_CELLS_PER_SCREEN_WIDTH / 2) - 1;
const int MID_Y = (sim::MONITOR_CELLS_PER_SCREEN_HEIGHT / 2) - 1;
const int NUM_LINES = 4;
fill( BackgroundColor { 0x9 } );
auto drawCentered = [&] ( int lineIndex, const std::uint8_t* line, std::size_t length ) {
for ( std::size_t i = 0; i < length; ++i ) {
drawCell( MID_X - (length / 2) + i,
MID_Y - (NUM_LINES / 2) + lineIndex,
Character { line[i] },
ForegroundColor { 0xe },
BackgroundColor { 0x9 } );
}
};
const std::array<std::uint8_t, 14> LINE1 = { 'N', 'Y', 'A', ' ', 'E', 'L', 'E', 'K', 'T', 'R', 'I', 'S', 'K', 'A'};
const std::array<std::uint8_t, 7 > LINE2 = { 'L', 'E', 'M', '1', '8', '0', '2' };
const std::array<std::uint8_t, 18> LINE3 = {'L', 'o', 'w', ' ', 'E', 'n', 'e', 'r', 'g', 'y', ' ', 'M', 'o', 'n', 'i', 't', 'o', 'r' };
drawCentered( 0, LINE1.data(), LINE1.size() );
drawCentered( 2, LINE2.data(), LINE2.size() );
drawCentered( 3, LINE3.data(), LINE3.size() );
}
示例2: PrettyPrint
inline std::string PrettyPrint(const std::array<T, N>& arraytoprint, const bool add_delimiters=false, const std::string& separator=", ")
{
std::ostringstream strm;
if (arraytoprint.size() > 0)
{
if (add_delimiters)
{
strm << "[" << PrettyPrint(arraytoprint[0], add_delimiters, separator);
for (size_t idx = 1; idx < arraytoprint.size(); idx++)
{
strm << separator << PrettyPrint(arraytoprint[idx], add_delimiters, separator);
}
strm << "]";
}
else
{
strm << PrettyPrint(arraytoprint[0], add_delimiters, separator);
for (size_t idx = 1; idx < arraytoprint.size(); idx++)
{
strm << separator << PrettyPrint(arraytoprint[idx], add_delimiters, separator);
}
}
}
return strm.str();
}
示例3: test_case_from_const_std_array_constructor
void test_case_from_const_std_array_constructor()
{
const std::array<int, 4> arr = {1, 2, 3, 4};
{
span<const int> s{arr};
CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
}
{
span<const int, 4> s{arr};
CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
}
CONCEPT_ASSERT(!std::is_constructible<span<const int, 2>, decltype((arr))>::value);
CONCEPT_ASSERT(!std::is_constructible<span<const int, 0>, decltype((arr))>::value);
CONCEPT_ASSERT(!std::is_constructible<span<const int, 5>, decltype((arr))>::value);
{
auto get_an_array = []() -> const std::array<int, 4> { return {1, 2, 3, 4}; };
auto take_a_span = [](span<const int>) {};
take_a_span(get_an_array());
}
{
auto s = make_span(arr);
CHECK((s.size() == narrow_cast<std::ptrdiff_t>(arr.size()) && s.data() == arr.data()));
}
}
示例4: if
static void
parseRegisterValue(std::array<latte::SPI_VS_OUT_ID_N, 10> &spi_vs_out_id,
uint32_t index,
const std::string &member,
const std::string &value)
{
if (index >= spi_vs_out_id.size()) {
throw gfd_header_parse_exception {
fmt::format("SQ_VTX_SEMANTIC[{}] invalid index, max: {}",
index, spi_vs_out_id.size())
};
}
if (member == "SEMANTIC_0") {
spi_vs_out_id[index] = spi_vs_out_id[index]
.SEMANTIC_0(parseValueNumber(value));
} else if (member == "SEMANTIC_1") {
spi_vs_out_id[index] = spi_vs_out_id[index]
.SEMANTIC_1(parseValueNumber(value));
} else if (member == "SEMANTIC_2") {
spi_vs_out_id[index] = spi_vs_out_id[index]
.SEMANTIC_2(parseValueNumber(value));
} else if (member == "SEMANTIC_3") {
spi_vs_out_id[index] = spi_vs_out_id[index]
.SEMANTIC_3(parseValueNumber(value));
} else {
throw gfd_header_parse_exception {
fmt::format("SPI_VS_OUT_ID[{}] does not have member {}",
index, member)
};
}
}
示例5: main
int main(int argc, char** argv)
{
// ut::setLogLevel(ut::LOGLEVEL_DEBUG);
size_t selected = 0;
if (argc == 2) {
selected = boost::lexical_cast<size_t>(argv[1]);
}
while (selected < 1 || EXAMPLES.size() < selected) {
printf ("Examples:\n\n");
for (size_t i = 0; i < EXAMPLES.size(); i++) {
printf ("%02d: %s\n", (int) (i + 1), EXAMPLES[i].second.c_str());
}
printf ("\nSelect: ");
try {
const char* line = readLine();
selected = boost::lexical_cast<size_t>(line);
} catch (...) {
}
printf ("\n---------\n\n");
}
auto& example = EXAMPLES[selected - 1];
example.first();
return 0;
}
示例6: validate_lines_information
bool fileinformation::validate_lines_information(std::string& line) {
std::smatch matches;
bool output = false;
std::size_t index;
static bool recursivecomment = false;
for(index = 0; index < regularexpression.size(); ++index) {
regularexpression[index].second = std::regex_search(line, matches, regularexpression[index].first);
/*
{
output = true;
if(index != 2){
break;
}
}
*/
}
recursivecomment = (regularexpression.at(2).second) && !(regularexpression.at(3).second);
for(index = 0; index < regularexpression.size(); ++index) {
regularexpression[index].second = false;
}
return output;
}
示例7: shift_line
score_t shift_line(std::array<cell_value_t*, board_size> &line)
{
score_t result = 0;
for (size_t i = 0; i < line.size(); /* nothing */) {
bool merged = false;
if ( *line[i] != 0 &&
i > 0 &&
*line[i-1] == *line[i])
{
*line[i-1] += 1;
*line[i] = 0;
merged = true;
// result += round(pow(SCORE_MERGE_BASE, *line[i-1]));
result += round((*line[i-1]) * SCORE_MERGE_FACTOR);
}
if (*line[i] == 0) {
bool shifted = false;
for (size_t j = i+1; j < line.size(); j++) {
if (*line[j] != 0) {
*line[i] = *line[j];
*line[j] = 0;
shifted = true;
break;
}
}
if (!shifted || merged) {
i++;
}
} else {
i++;
}
}
return result;
};
示例8: getTransformCombinations
std::vector<std::string> getTransformCombinations(std::array<std::string, 3> transformers, int iteration) {
std::vector<std::string> list;
std::vector<bool> v(transformers.size());
std::fill(v.begin() + iteration, v.end(), true);
do {
std::string tmp = "";
for (int i = 0; i < transformers.size(); ++i) {
if (!v[i]) {
if(tmp != "") {
tmp = tmp + "+";
}
tmp = tmp + transformers[i];
}
}
list.push_back(tmp);
} while (std::next_permutation(v.begin(), v.end()));
if(iteration < transformers.size()) {
std::vector<std::string> nlist;
nlist = getTransformCombinations(transformers, iteration+1);
for(std::string s : nlist) {
list.push_back(s);
}
}
return list;
}
示例9: main
int main()
{
const std::array<int, 3> arr { 1, 2, 3 };
std::array<int, arr.size()> arr2;
std::cout << arr.size() << arr2.size() << std::endl;
}
示例10: getIndexForConfTarget
int getIndexForConfTarget(int target) {
for (unsigned int i = 0; i < confTargets.size(); i++) {
if (confTargets[i] >= target) {
return i;
}
}
return confTargets.size() - 1;
}
示例11: toNormalizedFromValue
virtual double toNormalizedFromValue(double x) override
{
for (int i = 0; i<c_fft_sizes.size() - 1; ++i)
{
if (x >= c_fft_sizes[i] && x<c_fft_sizes[i + 1])
return 1.0 / c_fft_sizes.size() *i;
}
return 0.0;
}
示例12: assert
const char *Init(JSContext *ctx, unsigned ID){
assert(ctx);
assert(function_name_list.size() == function_list.size());
Network::socket_proto.initForContext(ctx, nullptr, socket_methods);
Network::listening_socket_proto.initForContext(ctx, nullptr, listening_socket_methods);
return PLUGINNAME;
}
示例13: operator
size_t operator()(const std::array<size_t, dims> &arr) const noexcept
{
size_t result = arr.size();
for (size_t i = 0; i < arr.size(); i++)
{
result *= result * 63 + arr[i];
}
return result;
}
示例14:
blit_saw_oscillator()
:pitchbend(0.0)
{
// sine wave table
for (size_t ii = 0; ii < sin_table.size(); ii++)
{
sin_table[ii] = std::sin(2.0*PI * ii / (sin_table.size() - 1));
}
}
示例15:
shared_byte_allocator& _get_alloc(span_size_t align) {
assert(_alignment.size() == _aligned_alloc.size());
for(std::size_t i=0; i<_alignment.size(); ++i) {
if(_alignment[i] == align) {
return _aligned_alloc[i];
}
}
return _fallback_alloc;
}