compare_string_type.pass.cpp revision 6dfff1c9b9147641601574c953e208ece17f27d8
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <regex>
11
12// template <class BidirectionalIterator> class sub_match;
13
14// int compare(const string_type& s) const;
15
16#include <regex>
17#include <cassert>
18#include "test_macros.h"
19
20int main()
21{
22    {
23        typedef char CharT;
24        typedef std::sub_match<const CharT*> SM;
25        typedef SM::string_type string;
26        SM sm = SM();
27        SM sm2 = SM();
28        assert(sm.compare(string()) == 0);
29        const CharT s[] = {'1', '2', '3', 0};
30        sm.first = s;
31        sm.second = s + 3;
32        sm.matched = true;
33        assert(sm.compare(string()) > 0);
34        assert(sm.compare(string("123")) == 0);
35    }
36    {
37        typedef wchar_t CharT;
38        typedef std::sub_match<const CharT*> SM;
39        typedef SM::string_type string;
40        SM sm = SM();
41        SM sm2 = SM();
42        assert(sm.compare(string()) == 0);
43        const CharT s[] = {'1', '2', '3', 0};
44        sm.first = s;
45        sm.second = s + 3;
46        sm.matched = true;
47        assert(sm.compare(string()) > 0);
48        assert(sm.compare(string(L"123")) == 0);
49    }
50}
51