# A proposal to add Unicode code unit sequence container to C++

## Motivation

## Design goals

## Design decisions

Use [strong types](https://github.com/Lyberta/cpp-unicode-fundamental).

Based on `std::vector`

No `std::char_traits`

`size_type` and `difference_type` are defined from allocator as in `std::basic_string`.

Use `InputIterator` concept.

TODO: Ranges

Code units are passed by value.

`emplace` and `emplace_back` to help with explicit ctors.

Non-null-terminated. No `c_str()`.

## Header `<unicode>` synopsis

	namespace std::unicode
	{
	
	template <typename T, typename Allocator = std::allocator<T>>
	class code_unit_sequence;
	
	using utf8_code_unit_sequence = code_unit_sequence<utf8_code_unit>;
	using utf16_code_unit_sequence = code_unit_sequence<utf16_code_unit>;
	using utf32_code_unit_sequence = code_unit_sequence<utf32_code_unit>;

	}

## Class template `code_unit_sequence`

	template <typename T, typename Allocator = std::allocator<T>>
	class code_unit_sequence final
	{
	public:
		// Types
		using value_type = T;
		using allocator_type = Allocator;
		using pointer = typename std::allocator_traits<Allocator>::pointer;
		using const_pointer =
			typename std::allocator_traits<Allocator>::const_pointer;
		using reference = value_type&;
		using const_reference = const value_type&;
		using size_type = typename std::allocator_traits<Allocator>::size_type;
		using difference_type =
			typename std::allocator_traits<Allocator>::difference_type;
		using iterator = implementation-defined;
		using const_iterator = implementation-defined;
		using reverse_iterator = std::reverse_iterator<iterator>;
		using const_reverse_iterator = std::reverse_iterator<const_iterator>;
		
		// Construct/copy/destroy
		code_unit_sequence() noexcept(noexcept(Allocator{}));
		explicit code_unit_sequence(const Allocator& allocator) noexcept;
		explicit code_unit_sequence(size_type amount,
			const Allocator& allocator = Allocator());
		code_unit_sequence(size_type amount, value_type code_unit,
			const Allocator& allocator = Allocator{});
		template <InputIterator I>
		code_unit_sequence(I first, I last, const Allocator& allocator =
			Allocator{});
		code_unit_sequence(const code_unit_sequence& other);
		code_unit_sequence(code_unit_sequence&& other) noexcept;
		code_unit_sequence(const code_unit_sequence& other,
			const Allocator& allocator);
		code_unit_sequence(code_unit_sequence&& other, const Allocator& allocator);
		code_unit_sequence(std::initializer_list<T> code_units,
			const Allocator& allocator = Allocator{});
		~code_unit_sequence();
		code_unit_sequence& operator=(const code_unit_sequence& other);
		code_unit_sequence& operator=(code_unit_sequence&& other) noexcept(
			std::allocator_traits<Allocator>::
			propagate_on_container_move_assignment::value ||
			std::allocator_traits<Allocator>::is_always_equal::value);
		code_unit_sequence& operator=(std::initializer_list<T> code_units);
		template <InputIterator I>
		void assign(I first, I last);
		void assign(size_type amount, value_type code_unit);
		void assign(std::initializer_list<T> code_units);
		allocator_type get_allocator() const noexcept;
		
		// Iterators
		iterator begin() noexcept;
		const_iterator begin() const noexcept;
		iterator end() noexcept;
		const_iterator end() const noexcept;
		reverse_iterator rbegin() noexcept;
		const_reverse_iterator rbegin() const noexcept;
		reverse_iterator rend() noexcept;
		const_reverse_iterator rend() const noexcept;
		const_iterator cbegin() const noexcept;
		const_iterator cend() const noexcept;
		const_reverse_iterator crbegin() const noexcept;
		const_reverse_iterator crend() const noexcept;
		
		// Capacity
		[[nodiscard]] bool empty() const noexcept;
		size_type size() const noexcept;
		size_type max_size() const noexcept;
		size_type capacity() const noexcept;
		void resize(size_type new_size);
		void resize(size_type new_size, value_type code_unit);
		void reserve(size_type new_capacity);
		void shrink_to_fit();
		
		// Element access
		reference operator[](size_type index);
		const_reference operator[](size_type index) const;
		reference at(size_type index);
		const_reference at(size_type index) const;
		reference front();
		const_reference front() const;
		reference back();
		const_reference back() const;
		
		// Data access
		T* data() noexcept;
		const T* data() const noexcept;
		
		// Modifiers
		template <typename... Args>
		reference emplace_back(Args&&... args);
		void push_back(T code_unit);
		void pop_back();
		template <typename... Args>
		iterator emplace(const_iterator position, Args&&... args);
		iterator insert(const_iterator position, T code_unit);
		iterator insert(const_iterator position, size_type amount, T code_unit);
		template <InputIterator I>
		iterator insert(const_iterator position, I first, I last);
		iterator insert(const_iterator position,
			std::initializer_list<T> code_units);
		iterator erase(const_iterator position);
		iterator erase(const_iterator first, const_iterator last);
		void swap(code_unit_sequence& other) noexcept(
			std::allocator_traits<Allocator>::propagate_on_container_swap::value ||
			std::allocator_traits<Allocator>::is_always_equal::value);
		void clear() noexcept;
	};


