GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
deductionguidesforstd::basic_string(3) C++ Standard Libary deductionguidesforstd::basic_string(3)

deductionguidesforstd::basic_string - deductionguidesforstd::basic_string


Defined in header <string>
template< class InputIt, class Alloc = std::allocator<


typename std::iterator_traits<InputIt>::value_type> >
basic_string( InputIt, InputIt, Alloc = Alloc() )
-> basic_string<typename (1) (since C++17)
std::iterator_traits<InputIt>::value_type,
std::char_traits<typename
std::iterator_traits<InputIt>::value_type>,


Alloc>;
template< class CharT,


class Traits,
class Alloc = std::allocator<CharT> > (2) (since C++17)
explicit basic_string( std::basic_string_view<CharT, Traits>,
const Alloc& = Alloc() )


-> basic_string<CharT, Traits, Alloc>;
template< class CharT,


class Traits,
class Alloc = std::allocator<CharT>> >
basic_string( std::basic_string_view<CharT, Traits>, typename (3) (since C++17)
/*see below*/::size_type,
typename /*see below*/::size_type, const Alloc& = Alloc() )


-> basic_string<CharT, Traits, Alloc>;


1) This deduction guide is provided for std::basic_string to allow deduction from an
iterator range. This overload participates in overload resolution only if InputIt
satisfies LegacyInputIterator and Alloc satisfies Allocator.
2-3) These deduction guides are provided for std::basic_string to allow deduction
from a std::basic_string_view. The size_type parameter type in (3) refers to the
size_type member type of the type deduced by the deduction guide. These overloads
participate in overload resolution only if Alloc satisfies Allocator.


Note: the extent to which the library determines that a type does not satisfy
LegacyInputIterator is unspecified, except that as a minimum integral types do not
qualify as input iterators. Likewise, the extent to which it determines that a type
does not satisfy Allocator is unspecified, except that as a minimum the member type
Alloc::value_type must exist and the expression
std::declval<Alloc&>().allocate(std::size_t{}) must be well-formed when treated as
an unevaluated operand.


Guides (2-3) are needed because the std::basic_string constructors for
std::basic_string_views are made templates to avoid causing ambiguities in existing
code, and those templates do not support class template argument deduction.

// Run this code


#include <string>
#include <vector>
int main() {
std::vector<char> v = {'a', 'b', 'c'};
std::basic_string s(v.begin(), v.end()); // uses explicit deduction guide
}


Defect reports


The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.


DR Applied to Behavior as published Correct behavior
LWG 3075 C++17 deduction from basic_string_view was deduction guides
unsupported (exacerbated by LWG issue 2946) added

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.