---
name: "ACE_Array_Base"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_Array_Base"
---

# ACE\_Array\_Base(3)

Implement a simple dynamic array

## NAME

ACE\_Array\_Base -  Implement a simple dynamic array

## SYNOPSIS

```
#include <ace/Containers.h>
template<class T>
class ACE_Array_Base
{
  public:
    typedef T TYPE;
    typedef ACE_Array_Iterator<T> ITERATOR;
    ACE_Array_Base (size_t size = 0, ACE_Allocator *alloc = 0);
    ACE_Array_Base (
        size_t size,
        const T &default_value,
        ACE_Allocator *alloc = 0
        );
    ACE_Array_Base (const ACE_Array_Base<T> &s);
    void operator= (const ACE_Array_Base<T> &s);
    ~ACE_Array_Base (void);
    T &operator [] (size_t slot);
    const T &operator [] (size_t slot) const;
    int set (const T &new_item, size_t slot);
    int get (T &item, size_t slot) const;
    size_t size (void) const;
    int size (size_t new_size);
    size_t max_size (void) const;
    int max_size (size_t new_size);
  private:
    int in_range (size_t slot) const;
    size_t max_size_;
    size_t cur_size_;
    T *array_;
    ACE_Allocator *allocator_;
    friend class ACE_Array_Iterator<T>;
};
```

## DESCRIPTION

This implementation of an unordered set uses a fixed array. This implementation does not allow duplicates...

## Initialization and termination methods.

```
ACE_Array_Base (size_t size = 0, ACE_Allocator *alloc = 0);
```

Dynamically create an uninitialized array.

```
ACE_Array_Base (
    size_t size,
    const T &default_value,
    ACE_Allocator *alloc = 0
    );
```

Dynamically initialize the entire array to the default\_value.

```
ACE_Array_Base (const ACE_Array_Base<T> &s);
```

The copy constructor performs initialization by making an exact copy of the contents of parameter s, i.e., \*this == s will return true.

```
void operator= (const ACE_Array_Base<T> &s);
```

Assignment operator performs an assignment by making an exact copy of the contents of parameter s, i.e., \*this == s will return true.  Note that if the max\_size\_ of array\_ is = than s.max\_size\_ we can copy it without reallocating.  However, if max\_size\_ is  s.max\_size\_ we must delete the array\_, reallocate a new array\_, and then copy the contents of s.

```
~ACE_Array_Base (void);
```

Clean up the array (e.g., delete dynamically allocated memory).

## Set/get methods.

```
T &operator [] (size_t slot);
```

Set item in the array at location slot.  Doesn't perform range checking.

```
const T &operator [] (size_t slot) const;
```

Get item in the array at location slot.  Doesn't perform range checking.

```
int set (const T &new_item, size_t slot);
```

Set an item in the array at location slot.  Returns -1 if slot is not in range, else returns 0.

```
int get (T &item, size_t slot) const;
```

Get an item in the array at location slot.  Returns -1 if slot is not in range, else returns 0.  Note that this function copies the item.  If you want to avoid the copy, you can use the const operator \[\], but then you'll be responsible for range checking.

```
size_t size (void) const;
```

Returns the cur\_size\_ of the array.

```
int size (size_t new_size);
```

Changes the size of the array to match new\_size. It copies the old contents into the new array. Return -1 on failure.

```
size_t max_size (void) const;
```

Returns the max\_size\_ of the array.

```
int max_size (size_t new_size);
```

Changes the size of the array to match new\_size. It copies the old contents into the new array. Return -1 on failure. It does not affect new\_size

## AUTHOR

Doug Schmidt

## Initialization and termination methods.

## Check boundary conditions.

## Classic unordered set operations.

## LIBRARY

ace
