[#name_generator_sha1]
== <boost/uuid/{zwsp}name_generator_sha1.hpp>

:idprefix: name_generator_sha1_

=== Synopsis

[source,c++]
----
#include <boost/uuid/namespaces.hpp>

namespace boost {
namespace uuids {

class name_generator_sha1
{
public:

    using result_type = uuid;

    explicit name_generator_sha1( uuid const& namespace_uuid ) noexcept;

    template<class Ch> uuid operator()( Ch const* name ) const noexcept;

    template<class Ch, class Traits, class Alloc>
      uuid operator()( std::basic_string<Ch, Traits, Alloc> const& name ) const noexcept;

    uuid operator()( void const* buffer, std::size_t byte_count ) const noexcept;
};

}} // namespace boost::uuids
----

=== name_generator_sha1

The class `name_generator_sha1` generates name-based version 5 UUIDs, using SHA1 as the hashing algorithm.

```
explicit name_generator_sha1( uuid const& namespace_uuid );
```

Effects: :: Constructs a `name_generator_sha1` that uses `namespace_uuid` as the namespace.

```
template<class Ch> uuid operator()( Ch const* name ) const noexcept;
```

Requires: :: `Ch` must be one of `char`, `wchar_t`, `char8_t`, `char16_t`, or `char32_t`.

Returns: :: A name-based UUID version 5 produced from a digest of the namespace passed to the constructor and the characters of the string `name`, converted to octets.

Remarks: :: The characters of `name` are converted to a sequence of octets in the following manner:
+
* If `Ch` is `char` or `char8_t`, the characters are processed as octets directly.
* If `Ch` is `wchar_t`, the characters are converted to `uint32_t` and then serialized to four octets each using little-endian representation.
* Otherwise, the character sequence is converted to UTF-8 and the result is processed as octets.

Example: ::
+
```
using namespace boost::uuids;

name_generator_sha1 gen( ns::dns() );

uuid u1 = gen( "boost.org" );

std::cout << "\"boost.org\" UUID in DNS namespace, SHA1 version: " << u1 << std::endl;

// Output:
//   "boost.org" UUID in DNS namespace, SHA1 version: 0043f363-bbb4-5369-840a-322df6ec1926

uuid u2 = gen( L"boost.org" );

std::cout << "L\"boost.org\" UUID in DNS namespace, SHA1 version: " << u2 << std::endl;

// Output:
//   L"boost.org" UUID in DNS namespace, SHA1 version: c31c5016-3493-5dc2-8484-5813d495cc18

uuid u3 = gen( u"boost.org" );

std::cout << "u\"boost.org\" UUID in DNS namespace, SHA1 version: " << u3 << std::endl;

// Output:
//   u"boost.org" UUID in DNS namespace, SHA1 version: 0043f363-bbb4-5369-840a-322df6ec1926
```

```
template<class Ch, class Traits, class Alloc>
  uuid operator()( std::basic_string<Ch, Traits, Alloc> const& name ) const;
```

Requires: :: `Ch` must be one of `char`, `wchar_t`, `char8_t`, `char16_t`, or `char32_t`.

Returns: :: As if `operator()( name.c_str() )`.

```
uuid operator()( void const* buffer, std::size_t byte_count ) const;
```

Returns: :: A name-based UUID version 5 produced from a digest of the namespace passed to the constructor and the `byte_count` octets starting from `buffer`.
