void add_rule(Addr first, Addr last, std::uint32_t const flags) { TORRENT_ASSERT(!m_access_list.empty()); TORRENT_ASSERT(first < last || first == last); auto i = m_access_list.upper_bound(first); auto j = m_access_list.upper_bound(last); if (i != m_access_list.begin()) --i; TORRENT_ASSERT(j != m_access_list.begin()); TORRENT_ASSERT(j != i); std::uint32_t first_access = i->access; std::uint32_t last_access = std::prev(j)->access; if (i->start != first && first_access != flags) { i = m_access_list.insert(i, range(first, flags)); } else if (i != m_access_list.begin() && std::prev(i)->access == flags) { --i; first_access = i->access; } TORRENT_ASSERT(!m_access_list.empty()); TORRENT_ASSERT(i != m_access_list.end()); if (i != j) m_access_list.erase(std::next(i), j); if (i->start == first) { // we can do this const-cast because we know that the new // start address will keep the set correctly ordered const_cast<Addr&>(i->start) = first; const_cast<std::uint32_t&>(i->access) = flags; } else if (first_access != flags) { m_access_list.insert(i, range(first, flags)); } if ((j != m_access_list.end() && minus_one(j->start) != last) || (j == m_access_list.end() && last != max_addr<Addr>())) { TORRENT_ASSERT(j == m_access_list.end() || last < minus_one(j->start)); if (last_access != flags) j = m_access_list.insert(j, range(plus_one(last), last_access)); } if (j != m_access_list.end() && j->access == flags) m_access_list.erase(j); TORRENT_ASSERT(!m_access_list.empty()); }
static void example_drv_output(ErlDrvData handle, char *buff, int bufflen) { example_data* d = (example_data*)handle; char fn = buff[0], arg = buff[1], res; if (fn == 1) { res = plus_one(arg); } else if (fn == 2) { res = times_two(arg); } driver_output(d->port, &res, 1); }
int main(void) { int prediction = will_overflow(INT_MAX); int actual = plus_one(INT_MAX) == INT_MIN; if (prediction == actual) { printf("SUCCESS\n"); } else { printf("FAILURE\n"); } return 0; }
int main() { int result = plus_one(5); printf("%d\n", result); char sign = get_sign(-5); printf("Sign of %d is %c\n", -5, sign); printf("Celius: %.2f\n", fahrenheit_to_celsius(44)); printf("%.2f^%d = %.2f\n", 3.0, 3, power(3.0, 3)); double triangleArea = calc_triangle_area(3, 4); printf("Area: %.2f", triangleArea); return (EXIT_SUCCESS); }
int main(int argc, char** argv) { if (argc != 2) { std::cout << "usage: " << argv[0] << " <integer>" << std::endl; return 1; } int num_digits = std::strlen(argv[1]); int array[num_digits]; for (int i = 0; i < num_digits; ++i) { array[i] = argv[1][i] - '0'; } std::cout << "digits provided: " << utils::array_to_string(array, num_digits) << std::endl; std::cout << "digits plus one: " << utils::array_to_string(plus_one(array, num_digits), num_digits) << std::endl; return 0; }
//////////////////////////////////////////////////////////////////////////////// // Test boost::simd::transform behavior with unary operation //////////////////////////////////////////////////////////////////////////////// NT2_TEST_CASE_TPL( transform_unary, BOOST_SIMD_SIMD_TYPES ) { std::vector<T> data_in(113); for(size_t i=0; i<113; ++i) data_in[i] = T(i); std::vector<T> data_out1(113); boost::simd::transform(&*data_in.begin(), &*data_in.begin()+data_in.size(), &*data_out1.begin(), plus_one()); std::vector<T> data_out2(113); std::transform(&*data_in.begin(), &*data_in.begin()+data_in.size(), &*data_out2.begin(), plus_one()); NT2_TEST_EQUAL(data_out1, data_out2); }