static void a_copy_test(void) {
	printsln((String)__func__);
	Array array, copy;

	array = sa_of_string("-1, -2, -3");
	copy = a_copy(array);
	sa_check_expect(copy, array);
	sa_free(array);
	a_free(copy);

	array = sa_of_string("10");
	copy = a_copy(array);
	sa_check_expect(copy, array);
	sa_free(array);
	a_free(copy);

	array = sa_of_string("100, -200");
	copy = a_copy(array);
	sa_check_expect(copy, array);
	sa_free(array);
	a_free(copy);

	array = sa_of_string("");
	copy = a_copy(array);
	sa_check_expect(copy, array);
	sa_free(array);
	a_free(copy);
}
示例#2
0
文件: array.c 项目: semenovf/cwt
static CwtArray* a_clone (CwtArray *a)
{
	if (a) {
		CwtArray *clone;
		clone = a_alloc(a->sizeof_item, a->capacity);
		a_copy(clone, a, 0, 0, a->capacity);
		return clone;
	}

	return NULL;
}
 void destroy() // nothrow
 {
    //Self destruction, so move the allocator
    this_allocator a_copy(::boost::move(static_cast<this_allocator&>(*this)));
    BOOST_ASSERT(a_copy == *this);
    this_pointer this_ptr(this_pointer_traits::pointer_to(*this));
    //Do it now!
    scoped_ptr< this_type, scoped_ptr_dealloc_functor<this_allocator> >
       deleter_ptr(this_ptr, a_copy);
    typedef typename this_allocator::value_type value_type;
    ipcdetail::to_raw_pointer(this_ptr)->~value_type();
 }
示例#4
0
 void destroy() // nothrow
 {
    //Self destruction, so get a copy of the allocator
    //(in the future we could move it)
    this_allocator a_copy(*this);
    BOOST_ASSERT(a_copy == *this);
    this_pointer this_ptr (this);
    //Do it now!
    scoped_ptr< this_type, scoped_ptr_dealloc_functor<this_allocator> >
       deleter(this_ptr, a_copy);
    typedef typename this_allocator::value_type value_type;
    ipcdetail::to_raw_pointer(this_ptr)->~value_type();
 }
示例#5
0
harglst*
harg_dup
  (harglst*    a,
   unsigned size)
{
  copy_cb desc ;
  harg data ;

  /* sanity check */
  if (a == 0) {
    errno = EINVAL;
    return 0; 
  }

  desc.trg         = 0 ;
  desc.depth       = 0 ;
  data.type        = HARG_HARG ;
  data.d.d.ptr [0] = a ;

  return (harglst*)a_copy (&desc, &data, 0, 0);
}
示例#6
0
static void a_copy_test(void) {
	printsln((String)__func__);
	Array array, copy;
	Address a;
	
	array = a_create(3, sizeof(Address));
	a = make_address("Fred", "Oyster", "Hannover");
	a_set(array, 0, &a);
	a = make_address("Frida", "Qwirin", "Hannover");
	a_set(array, 1, &a);
	a = make_address("James", "Bond", "London");
	a_set(array, 2, &a);

	copy = a_copy(array);
	a_check_expect(copy, array);
	
	a_free(array);
	a_free(copy);

	array = ia_of_string("-1, -2, -3");
	copy = a_copy(array);
	ia_check_expect(copy, array);
	a_free(array);
	a_free(copy);

	array = ia_of_string("10");
	copy = a_copy(array);
	ia_check_expect(copy, array);
	a_free(array);
	a_free(copy);

	array = ia_of_string("100, -200");
	copy = a_copy(array);
	ia_check_expect(copy, array);
	a_free(array);
	a_free(copy);

	array = ia_of_string("");
	copy = a_copy(array);
	ia_check_expect(copy, array);
	a_free(array);
	a_free(copy);

	array = da_of_string("-1, -2, -3");
	copy = a_copy(array);
	da_check_within(array, copy);
	a_free(array);
	a_free(copy);
	array = da_of_string("10");
	copy = a_copy(array);
	da_check_within(array, copy);
	a_free(array);
	a_free(copy);
	array = da_of_string(" 100, -200 ");
	copy = a_copy(array);
	da_check_within(array, copy);
	a_free(array);
	a_free(copy);
	array = da_of_string("");
	copy = a_copy(array);
	da_check_within(array, copy);
	a_free(array);
	a_free(copy);
}
示例#7
0
int main() {

    int x = 10;
    const int cx = 10;
    str y;
    const str cy;

    //constuctors

    any a0;

    any a_T_small0 (x);
    any a_T_small1(cx);
    any a_T_small2(10);

    any a_T_big0(y);
    any a_T_big1(cy);
    any a_T_big2(std::move(y));

    //copy constructors

    any a_copy(a0);

    const any a_copy_small0(a_T_small0);
    any a_copy_small1(a_copy_small0);
    any a_copy_small2(std::move(a_copy_small1));

    const any a_copy_big0(a_T_big0);
    any a_copy_big1(a_copy_big0);
    any a_copy_big2(std::move(a_copy_big1));

    //operator=

    a_T_small0 = a_T_small1;
    a_T_small2 = a_T_big2;
    a_copy_big2 = a_copy_small2;
    a_T_big1 = a_T_big0;

    //good casts

    std::cout << "good casts (small): ";

    std::cout << *any_cast<int>(&a_T_small0) << " ";
    std::cout << *any_cast<int>(&a_copy_small0) << " ";
    std::cout << any_cast<int>(a_T_small0) << " ";
    std::cout << any_cast<int>(a_copy_small0) << " ";
    std::cout << any_cast<int>(std::move(a_T_small0)) << " ";

    std::cout << "\ngood casts (big): ";

    std::cout << any_cast<str>(&a_T_big0)->a << " ";
    std::cout << any_cast<str>(&a_copy_big0)->a << " ";
    std::cout << any_cast<str>(a_T_big0).a << " ";
    std::cout << any_cast<str>(a_copy_big0).a << " ";
    std::cout << any_cast<str>(std::move(a_T_big0)).a << " ";

    //bad casts

    std::cout << "\nbad casts: ";

    std::cout << (any_cast<double>(&a_T_small0) == nullptr) << " ";
    std::cout << (any_cast<other_str>(&a_copy_big0) == nullptr) << " ";
    try {
        any_cast<other_str>(a_T_big0);
    } catch(std::bad_cast& e) {
        std::cout << "1 ";
    }
    try {
        any_cast<double>(a_copy_small0);
    } catch(std::bad_cast& e) {
        std::cout << "1 ";
    }
    try {
        any_cast<int>(std::move(a0));
    } catch(std::bad_cast& e) {
        std::cout << "1 ";
    }
    return 0;
}